jtourlamain (5) [Avatar] Offline

This is the first book about F# that makes me curious to read on. Great read so far!

In listing 15.3 you have

let customersByCity = List.groupBy (fun c -> c.City) customerList
let customersByCountry = customerList |> List.groupBy (fun c -> c.Country)

I understand that they are essentially the same (as you write it in your book), but is one way preferred over the other, or when should I use the first syntax and when the second one?

Thanks for the feedback

Jan Tourlamain
Isaac Abraham (107) [Avatar] Offline
Great question. I think I mention it (somewhere!) in the book, but there's no right or wrong here. My personal view (and what seems to be the most popular in F# generally) is to always use the pipe operator for more than one operation e.g.

data | > List.map foo |> List.groupBy bar

Even for single operations, the piped version generally remains more popular - occasionally I do see people use the non-piped version - it saves a couple of typed characters smilie - but it doesn't happen very often.

I'm afraid that's about the best answer I can give.

Glad to see you're enjoying the book otherwise though!
jtourlamain (5) [Avatar] Offline
I appreciate the time you took to answer even a small question. Sometimes the answers on small questions help me find my way in a new coding adventure smilie
Thanks for the feedback!