Skip to content

Commit

Permalink
Simplified implementation of Zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucretiel committed May 13, 2016
1 parent 6cdbea9 commit b3e74a0
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions itertools.go
Expand Up @@ -349,19 +349,18 @@ func Starmap(fn MultiMapper, it Iter) Iter {
func Zip(its ...Iter) Iter {
c := make(Iter)
go func() {
Outer:
defer close(c)
for {
els := make([]interface{}, len(its))
for i, it := range its {
if el, ok := <- it; ok {
els[i] = el
} else {
break Outer
return
}
}
c <- els
}
close(c)
}()
return c
}
Expand Down Expand Up @@ -443,4 +442,4 @@ func Tee(it Iter, n int) []Iter {
func Tee2(it Iter) (Iter, Iter) {
iters := Tee(it, 2)
return iters[0], iters[1]
}
}

0 comments on commit b3e74a0

Please sign in to comment.