mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
Cursor.reduce(into:_:)
This commit is contained in:
1 parent
ac6b2933a8
commit
e4b83baa53
1 file changed
+22
-4
+22
-4
@@ -331,12 +331,30 @@ extension Cursor {
|
||||
|
||||
/// Returns the result of calling the given combining closure with each
|
||||
/// element of this cursor and an accumulating value.
|
||||
public func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Element) throws -> Result) throws -> Result {
|
||||
var result = initialResult
|
||||
public func reduce<Result>(
|
||||
_ initialResult: Result,
|
||||
_ nextPartialResult: (Result, Element) throws -> Result)
|
||||
throws -> Result
|
||||
{
|
||||
var accumulator = initialResult
|
||||
while let element = try next() {
|
||||
result = try nextPartialResult(result, element)
|
||||
accumulator = try nextPartialResult(accumulator, element)
|
||||
}
|
||||
return result
|
||||
return accumulator
|
||||
}
|
||||
|
||||
/// Returns the result of calling the given combining closure with each
|
||||
/// element of this cursor and an accumulating value.
|
||||
public func reduce<Result>(
|
||||
into initialResult: Result,
|
||||
_ updateAccumulatingResult: (inout Result, Element) throws -> Void)
|
||||
throws -> Result
|
||||
{
|
||||
var accumulator = initialResult
|
||||
while let element = try next() {
|
||||
try updateAccumulatingResult(&accumulator, element)
|
||||
}
|
||||
return accumulator
|
||||
}
|
||||
|
||||
/// Returns an array, up to the given maximum length, containing the
|
||||
|
||||
Reference in new issue
Block a user