1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Stream is a SequenceType.

This commit is contained in:
Rob Rix 2015-09-16 12:28:45 -04:00
parent 9c47dae557
commit 3bade61660

View File

@ -1,4 +1,4 @@
public enum Stream<A> { public enum Stream<A>: SequenceType {
case Nil case Nil
case Cons(A, () -> Stream) case Cons(A, () -> Stream)
@ -39,4 +39,14 @@ public enum Stream<A> {
public func map<B>(transform: A -> B) -> Stream<B> { public func map<B>(transform: A -> B) -> Stream<B> {
return uncons.map { first, rest in Stream<B>.Cons(transform(first), { rest.map(transform) }) } ?? Stream<B>.Nil return uncons.map { first, rest in Stream<B>.Cons(transform(first), { rest.map(transform) }) } ?? Stream<B>.Nil
} }
public func generate() -> AnyGenerator<A> {
var current = self
return anyGenerator {
let next = current.first
current = current.rest
return next
}
}
} }