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

Add a lazy right-fold to Stream.

This commit is contained in:
Rob Rix 2015-09-24 15:10:56 -04:00
parent abb625b501
commit 40211726bc

View File

@ -63,6 +63,13 @@ public enum Stream<A>: NilLiteralConvertible, SequenceType {
}
public func fold<Result>(initial: Result, combine: (A, Memo<Result>) -> Result) -> Result {
return analysis(
ifCons: { combine($0, $1.map { $0.fold(initial, combine: combine) }) },
ifNil: const(initial))
}
public init(nilLiteral: ()) {
self = .Nil
}