So the first and second methods came from this book , but I thought for fun I might reduce it further to see
how small a call could get.
Basically take a number and divide it by another number 3 times.
let bytesToGb item =
let itemB = item / 1024I
let itemC = itemB / 1024I
let itemD = itemC / 1024I
Is the same as:
let bytesToGb item =
let x = x / 1024I
let x = x / 1024I
let x = x / 1024I
And more reduction:
let bytesToGb item =
item
|> (fun x -> x/1024L)
|> (fun x -> x/1024L)
|> (fun x -> x/1024L)
Or more:
let divide x = x/1024L
let bytesToGb = divide >> divide >> divide
If you’re familiar with Func/Action, Linq, ect this might actually look a lot like some of the newer “functional like” additions to C#. Well at least the third one. Funny part, and I didn’t know this, is that most of the more interesting additions to C# (Generics, Linq, Lambda expressions) actually came from F#; Which was built to match other existing functional languages like Haskel)Â Go figure.