reductions(_:_:)
Returns a sequence containing the accumulated results of combining the elements of the sequence using the given closure.
func reductions<Result>(_ initial: Result, _ transform: @escaping (Result, Element) -> Result) -> ExclusiveReductionsSequence<Elements, Result>
Parameters
Returns
A sequence of the initial value followed by the reduced elements.
This can be seen as applying the reduce function to each element and providing the initial value followed by these results as a sequence.
let runningTotal = [1, 2, 3, 4].lazy.reductions(0, +)
print(Array(runningTotal))
// prints [0, 1, 3, 6, 10]