Crafting Code in F#

Howard Lewis wrote a nice post "Crafting Code in Clojure" about craftable code. He started with a rather ugly Java class and reached a lovely small Clojure solution. I was curious how it would be looked written in F#. Have a look at the result:

It's odd that F# core library does not contain Map.keys/Map.values functions. Otherwise, the code would be a bit more shorter.

However, maps aren't used in static languages like F# to represent domain types. Hence, the more idiomatic version:

(the Fact attribute is from xUnit.net library, and =? operator is from wonderful Unquote one).

Update 27.02.2018: Scala added

Very simple, very readable.

Comments

Popular posts from this blog

Haskell: performance

Regular expressions: Rust vs F# vs Scala

STM: F# vs Haskell