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:
parent
9c47dae557
commit
3bade61660
@ -1,4 +1,4 @@
|
||||
public enum Stream<A> {
|
||||
public enum Stream<A>: SequenceType {
|
||||
case Nil
|
||||
case Cons(A, () -> Stream)
|
||||
|
||||
@ -39,4 +39,14 @@ public enum Stream<A> {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
public func generate() -> AnyGenerator<A> {
|
||||
var current = self
|
||||
return anyGenerator {
|
||||
let next = current.first
|
||||
current = current.rest
|
||||
return next
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user