Skip to content

Instantly share code, notes, and snippets.

@poutyface
Created May 14, 2011 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poutyface/972373 to your computer and use it in GitHub Desktop.
Save poutyface/972373 to your computer and use it in GitHub Desktop.
arrow in ruby?
c = ->(arr, *fs){
arr.map{ |v| f = fs.empty? ? ->n{n} : fs.shift; Array(v).map(&f) }
}
p c.([[1,2],[3,4]], ->n{n+1}, ->n{n+1}) #=> [[2, 3], [4, 5]]
p c.([[1,2],[3,4]], ->n{n+1}) #=> [[2, 3], [3, 4]]
p c.([[1,2],[3,4]]) #=> [[1, 2], [3, 4]]
p c.([1,2], ->n{n+1}, ->n{n+1}) #=> [[2], [3]]
p c.([1,2], ->n{n+1}) #=> [[2], [2]]
p c.([1,2]) #=> [[1], [2]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment