Skip to content

Instantly share code, notes, and snippets.

@Adzz
Last active June 16, 2019 15:00
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 Adzz/166fa1b48bc196c0eddf9b6c12629678 to your computer and use it in GitHub Desktop.
Save Adzz/166fa1b48bc196c0eddf9b6c12629678 to your computer and use it in GitHub Desktop.
defimpl Zip, for: List do
def apply(a, b, operation) do
Enum.zip(a, b)
|> Enum.map(fn {a, b} -> operation.calculate(a, b) end)
end
end
# Now we can call it like this:
Zip.apply([1, 2], [3, 4], Add) #=> [4, 6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment