mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Add a lazy right-fold to Stream.
This commit is contained in:
parent
abb625b501
commit
40211726bc
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user