3 ms·
Refactoring Loops to Collection Pipelines
- VeejayRampay 11y agoEvery time I see code examples for operations like these, it reminds me of how nice Ruby is as a language. The blocks are concise, non-cryptic and could even shortened to .map(&:twitter_handle).compact
- Mithaldu 11y agoThat applies to all dynamic languages with useful list operations, really. Have an example in Ruby's forebear language: sub twitter_handles { my ( $authors, $company ) = @_; grep defined, map $_->twitter_handle, grep $_->company eq $company, @$authors; } This free book goes into the same kind of topic, only much more deep: http://hop.perl.plover.com/ http://hop.perl.plover.com/
- gclaramunt 11y agoThat applies to all languages with useful list operations :) (I don't think dynamic has any relation)
- willtim 11y agoWhy does Fowler always feel the need to invent his own terminology? A more accurate and accepted description for his examples would be "Stream combinators".
- clebio 11y agoI recently went looking for a Python implementation of the Javascript convention of operator chaining. In that search, I found an SO answer saying that it's called [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface https://en.wikipedia.org/wiki/Fluent_interface). Is this not the same thing?
- willtim 11y agoThis is indeed how most OO languages implement stream combinators (e.g. C#), but doesn't describe the F# and Clojure examples given.
- clebio 11y agoI admit some degree of ignorance, but the Wikipedia page I linked to has a C# example very similar to Fowler's final C# code: https://en.wikipedia.org/wiki/Fluent_interface#C.23 https://en.wikipedia.org/wiki/Fluent_interface#C.23 Am I missing some subtle difference?
- innguest 11y agoIf Martin Fowler and his piecemeal refactoring posts is what it'll take for the OO people to move out of State then I should thank Mr. Fowler.
- willtim 11y agoNo we should thank Erik Meijer for that :)