You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicextension Sequence
@inlinablefunc reduce(
_ nextPartialResult:(Element,Element)throws->Element)rethrows->Element?{variterator=makeIterator()returntry iterator.next().map{ first intryIteratorSequence(iterator).reduce(first, nextPartialResult)}}}
Typed throws should be used, however.
@inlinablefunc reduce<Error>(
_ nextPartialResult:(Element,Element)throws(Error)->Element)throws(Error)->Element?{variterator=makeIterator()returntry iterator.next().map{ first throws(Error)intryforceCastError(
to:Error.self,IteratorSequence(iterator).reduce(first, nextPartialResult))}}
/// A mechanism to interface between untyped and typed errors.
///
/// When you know for certain that a value may only throw one type of error,
/// but that guarantee is not (or, due to compiler bugs, cannot be) represented in the type system,
/// you can use this to "convert" it to "typed throws".
/// - Parameters:
/// - errorType: The error type known for certain to be thrown by `value`.
/// - value: A value that might throw an `Error`.
/// - Important: A crash will occur if `value` throws any type but `Error`.
/// - Bug: [`errorType` must be explicitly provided](https://github.com/swiftlang/swift/issues/75674).
publicfunc forceCastError<Value, Error>(
to errorType:Error.Type=Error.self,
_ value:@autoclosure()throws->Value)throws(Error)->Value{do{returntryvalue()}catch{throw error as!Error}}
The text was updated successfully, but these errors were encountered:
JessyCatterwaul
changed the title
The reduce overload to match reductions is missing.
One reduce overload to match reductions is missing.
Aug 29, 2024
Four of the six
reductions
overloads correspond to areduce
overload from the standard library.reduce
overload is missing.The missing overload should return
nil
, for empty sequences.Here's an implementation without typed throws:
Typed throws should be used, however.
The text was updated successfully, but these errors were encountered: