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:
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: ()) {
|
public init(nilLiteral: ()) {
|
||||||
self = .Nil
|
self = .Nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user