Refactoring with Loops and Collection Pipelines
martinfowler.com
martinfowler.com
I mean that's how things work, you don't have to invent anything, just make up some new expressions.
Let's be somewhat more charitable, and say "you don't have to invent anything, just provide an insight". Which is pretty reasonably, I think.
E.g. in python, you can't really 'pipe' to compose its filter and map built-ins, you have to do:
map(lambda x: x * 2,
filter(lambda x: x % 2 != 0, [1, 2, 3]))
(Or use list comprehensions which also are not pipe-like).He's also specifically talking about 'collections' as in 'lists of dicts' in Python parlance, or 'arrays of objects' in other languages.
The idea that you pass this 'collection' through a 'pipe' of operations is pretty powerful and obviously maps naturally to query-like behaviour. So to give Python back some dues, the place where you do of course see some 'collection piping' is when using the Django ORM.
So yeah it may sound a bit grandiose but I think he's highlighting those terms on purpose because it is about more than just map, filter and reduce.
mcoll - Modern API for python collections: https://github.com/nvbn/mcoll
I'd only previously come across underscore.py [0] (python port of underscore.js) which looked a little unmaintained though perhaps because it's 'done'.
def filter_authors(authors, company):
return [author['twitter_handle'] for author in authors if author['company'] == company and author['twitter_handle']]
EDIT: HN code formatting seems to be broken so you may need to scroll right to see the entire comprehension.You can do other SQL-like operations with list comprehensions too.
http://code.activestate.com/recipes/159974-sql-like-set-oper...
http://martinfowler.com/articles/collection-pipeline/
I also don't think he invented the term. A quick google search shows it's connected with LINQ.
Maybe he didn't invent the term, I don't know. It just feels to me like it's two words which, when used in combination, don't really add a whole lot of useful meaning to something that many of us will have been using for quite some years.
Maybe you don't like the name, but there's nothing unusual about this.
This is in sharp contrast to Python list comprehensions, which are very straight forward and understandable.