Created
March 17, 2012 03:03
-
-
Save bfabry/2054612 to your computer and use it in GitHub Desktop.
using inject to imitate method chaining with a right-fold
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = "blah blah blah" | |
ops = {:split => " ", :first => 2} | |
ops.to_a.reverse.inject(lambda {|x| x}) {|memo,(k,v)| lambda {|x| memo.call(x.send(k,v)) } }.call(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment