Skip to content

Instantly share code, notes, and snippets.

@bakkdoor
Created January 25, 2012 12:09
Show Gist options
  • Save bakkdoor/1675989 to your computer and use it in GitHub Desktop.
Save bakkdoor/1675989 to your computer and use it in GitHub Desktop.
chained #map: in Fancy (see https://gist.github.com/1675672)
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]]
@bakkdoor
Copy link
Author

@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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment