3 ms·
Half my code looks like this, these days: return products .Where(p => p.Type == ProductType.Bean) .OrderBy(p => p.Group) .ThenBy(p
by rikkus 12y ago
Half my code looks like this, these days:
return products
.Where(p => p.Type == ProductType.Bean)
.OrderBy(p => p.Group)
.ThenBy(p => p.Name)
.Select(p => p.Name)
;
Sometimes I'll write it like this:
return from p in Products
where p.ProductType == ProductType.Bean
orderby ... etc.
Everything's a query, or a sh pipeline, or...
One of the nice things about this idiom is that it's supported all over the place, so you can write similar code in many different languages, for many different platforms.
- balakk 12y agoHere's where F# shines - you could write your query like: products |> Seq.filter(fun a -> a.Type = ProductType.Bean) |> Seq.sortBy(fun a -> a.Group, a.Name) |> Seq.map(fun a -> a.Name) It doesn't save a lot of lines here, but the big difference is this: suddenly you aren't constrained by the syntax of the single Linq query. So you want an additional filter,join,merge happening in between? No problem!
- virtualwhys 12y agoPretty noisy. Instead of: products |> Seq.filter(fun a -> a.foo =...) In another language you can do: products.filter(_.foo =...) Those `|> Seq...(fun a ->` all over the place look Java-ish ;-)
- CmonDev 12y agoThey had to deal with the OCAML baggage instead of starting from scratch.
- pekk 12y agoIt is something you can do. It's fun to write. But is it better? Why?