3 ms·
> ghci> filter (\x -> (length x) > 2) ["a","bb","ccc","dddd"] ["ccc","dddd"]... I find the Haskell syntax concise and clear... > ["a","bb","ccc","dddd"].filt
by jonahx 3y ago
> ghci> filter (\x -> (length x) > 2) ["a","bb","ccc","dddd"]
["ccc","dddd"]... I find the Haskell syntax concise and clear...
> ["a","bb","ccc","dddd"].filter &(2.method(:<) << :length.to_proc)
I can't imagine a stronger case for GP's thesis. The point-free ruby rewrite is so baroque and needlessly circuitous... the extra variable is a far lesser evil, and more concise:
["a","bb","ccc","dddd"].filter { |x| x.length > 2 }
- inopinatus 3y agomy instinct is ["a","bb","ccc","dddd"].grep /.../ but then, I'm a recovering perl hacker
- jonahx 3y agoLove it!
- dragonwriter 3y agoYeah, mirroring the Haskell code, while possible in Ruby, is definitely not the best Ruby-aware approach, either for concision or clarity. The composability is available, but the problems where it is the best solution are different.