1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 00:44:57 +03:00

Add a constructor for single-element Streams.

This commit is contained in:
Rob Rix 2015-09-28 17:06:01 -04:00
parent 119fdaed78
commit 0c8303f27b

View File

@ -14,6 +14,10 @@ public enum Stream<A>: NilLiteralConvertible, SequenceType {
self = f().map { Stream.Cons($0, Memo { Stream(f) }) } ?? Stream.Nil
}
public static func pure(a: A) -> Stream {
return .Cons(a, Memo(evaluated: .Nil))
}
public func analysis<B>(@noescape ifCons ifCons: (A, Memo<Stream>) -> B, @noescape ifNil: () -> B) -> B {
switch self {
case let .Cons(first, rest):