Created
January 25, 2012 12:09
-
-
Save bakkdoor/1675989 to your computer and use it in GitHub Desktop.
chained #map: in Fancy (see https://gist.github.com/1675672)
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
class Fancy Enumerable { | |
def map_chained: blocks { | |
map: @{ | |
map: |v| { | |
blocks inject: v into: |acc b| { | |
b call: [acc] | |
} | |
} | |
} | |
} | |
} | |
# usage: | |
[[1],[2],[3]] map_chained: ('doubled, 'squared, @{ + 100 }) | |
# => [[104], [116], [136]] | |
# But I'd probably rather have this: | |
class Fancy Enumerable { | |
def map_chained: blocks { | |
map: |v| { | |
blocks inject: v into: |acc b| { | |
b call: [acc] | |
} | |
} | |
} | |
} | |
# and use it like this: | |
[1,2,3] map_chained: ('doubled, 'squared, @{ + 100 }) | |
# => [[104], [116], [136]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@sritchie check this out :)
this of course is completely different in terms of implementation (your's is for cascalog - this is just a normal method) but i think i'll add it to Fancy. Seems useful :)