Created
February 1, 2016 21:09
-
-
Save sideshowcoder/fdd5ec0678cae68a5fdc to your computer and use it in GitHub Desktop.
Coda Hales http://codahale.com/a-small-nice-thing/ in ruby
This file contains hidden or 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
| 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