1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +03:00

Stream zipping.

This commit is contained in:
Rob Rix 2015-09-25 13:57:35 -04:00
parent 00f1daa61a
commit da12af7313

View File

@ -74,6 +74,14 @@ public enum Stream<A>: NilLiteralConvertible, SequenceType {
}
public func zipWith<S: SequenceType>(sequence: S) -> Stream<(A, S.Generator.Element)> {
return Stream<(A, S.Generator.Element)>.unfold((self, Stream<S.Generator.Element>(sequence: sequence))) {
guard let (x, xs) = $0.uncons, (y, ys) = $1.uncons else { return nil }
return ((x, y), (xs.value, ys.value))
}
}
public init(nilLiteral: ()) {
self = .Nil
}