Skip to content

Instantly share code, notes, and snippets.

@josevalim
Created May 21, 2013 18: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 josevalim/5622231 to your computer and use it in GitHub Desktop.
Save josevalim/5622231 to your computer and use it in GitHub Desktop.
def zip(a, b) do
list = to_list(a)
throw do
{ zipped, rest } = Reducers.reduce(b, { [], list }, fn
entry, { acc, [h|t] } -> { [{entry, h}|acc], t }
entry, { acc, [] } -> throw { :enum_zip, acc }
end)
:lists.foldl(fn(x, acc) ->
[{ x, nil }|acc]
end, zipped, rest) |> :lists.reverse
catch
{ :enum_zip, rest } ->
:lists.reverse(rest)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment