Collection Pipeline
martinfowler.com
martinfowler.com
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.
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!
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 ;-) However the items this time are generic collection types
themselves - where an OO collection pipeline would use objects,
a functional language would use a hashmap.
Again, I'm a bit confused (though I might have missed some context). Functional languages tend to be much more generic so that a "collection pipeline" or map can operate over a wide range of types.I'm reasonably certain that I'm missing some critical point, but I'm not sure about what?
Otherwise known as inventing new terms for old concepts. Please stop doing this Mr Fowler! The programmer's glossary is already full of redundancy. Just stick to the language everyone else is using (ie, the language that was used by whoever wrote the original research papers in the given topics)
Stream is for me the fundamental nature of the unix pipeline, and this is rarely met in programming language (channels to the rescue like in Clojure and Go). The Java Streams seems to work this way with the distinction between stateless and stateful processing element (http://docs.oracle.com/javase/8/docs/api/java/util/stream/pa...).
Would expect to at least see some kind of discussion on this here - otherwise every method call is a "pipeline"
> ...returns a collection of only those articles for which the lambda resolves as true.
> Like select it returns a new collection so I can continue the pipeline...
> ...return a collection of records.
> Each operation takes a collection as an input and emits another collection (expect the last operation, which may be a terminal that emits a single value).