Coming from a OO (C#) background, I am trying to learn some FP. To help me transition, I am trying to learn F#. I am taking baby steps.
I set myself a simple challenge to count the instances of each letter in a sentence, ordered alphabetically. ("Hello World" -> "[D, 1]; [E, 1]; [H, 1]; [L, 3]; [O, 2]; [R, 1]; [W, 1]; ").
My solution works but I can't help but thinking that I am not able to break out of an imperative style (my solution is based on Linq type thinking).
open System let getLetterCount xs = xs |> Seq.filter Char.IsLetter |> Seq.map Char.ToUpper |> Seq.groupBy id |> Seq.sortBy fst |> Seq.map (fun (k,v) -> (k, Seq.length v)) let tuplesToString = Seq.fold (fun a (k,v) -> a + sprintf "[%c, %i]; " k v) "" printfn "%s" (tuplesToString (getLetterCount "Hello World"))
Does anyone know of a good source of challenges to help me get my teeth into learning this?