Skip to content

Instantly share code, notes, and snippets.

@citizen428
Created November 22, 2011 20:46
Show Gist options
  • Save citizen428/1386898 to your computer and use it in GitHub Desktop.
Save citizen428/1386898 to your computer and use it in GitHub Desktop.
Haskell's zip_with in Ruby
def zip_with(other, op=nil)
return [] if self.empty? || other.empty?
clipped = self[0..other.length-1]
zipped = clipped.zip(other)
if op
zipped.map { |a, b| a.send(op, b) }
else
zipped.map { |a, b| yield(a,b) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment