Created
June 6, 2018 15:24
-
-
Save haampie/c4eeb6fa1f6c0a48f44d7f14e010737e to your computer and use it in GitHub Desktop.
otherzip.jl
This file contains 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
module Zipperino | |
import Base: iterate, tail, @nexprs, @ntuple | |
using Test, Base.Iterators | |
struct LinearZip{N,T} | |
t::T | |
end | |
zip(a...) = LinearZip{length(a),typeof(a)}(a) | |
@generated function iterate(z::LinearZip{N}) where {N} | |
quote | |
@nexprs $N j -> begin | |
y_j = iterate(z.t[j]) | |
y_j === nothing && return nothing | |
end | |
values = @ntuple $N j->y_j[1] | |
states = @ntuple $N j->y_j[2] | |
values, states | |
end | |
end | |
@generated function iterate(z::LinearZip{N}, states) where {N} | |
quote | |
@nexprs $N j -> begin | |
y_j = iterate(z.t[j], states[j]) | |
y_j === nothing && return nothing | |
end | |
values = @ntuple $N j->y_j[1] | |
states = @ntuple $N j->y_j[2] | |
values, states | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment