Skip to content

Instantly share code, notes, and snippets.

@dharasim
Last active March 22, 2018 13:25
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 dharasim/4b80e70a78991ede5a1760aa3da91f8e to your computer and use it in GitHub Desktop.
Save dharasim/4b80e70a78991ede5a1760aa3da91f8e to your computer and use it in GitHub Desktop.
generic unzip function in julia
"""
unzip(iter)
unzip an iterable object of indexable objects
"""
function unzip(iter)
ntuple(length(first(iter))) do i
map(iter) do indexable
getindex(indexable, i)
end
end
end
# test
unzip([(1,2,3), (11,22,33)]) == ([1, 11], [2, 22], [3, 33])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment