Skip to content

Instantly share code, notes, and snippets.

@sideshowcoder
Created February 1, 2016 21:09
Show Gist options
  • Select an option

  • Save sideshowcoder/fdd5ec0678cae68a5fdc to your computer and use it in GitHub Desktop.

Select an option

Save sideshowcoder/fdd5ec0678cae68a5fdc to your computer and use it in GitHub Desktop.
a = [1,2,3]
b = [4,5,6]
# ruby can be quite functional sadly we don't have a sum by default
sum = lambda { |args| args.reduce(:+) }
# with this we can do
a.zip(b).map(&sum)
# extending does not change much
c = [7,8,9]
a.zip(b,c).map(&sum)
# Or with active support we have sum available
require "active_support/core_ext/enumerable"
a.zip(b,c).map(&:sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment