ReplaceErrorAsyncSequence
public struct ReplaceErrorAsyncSequence<Base> : AsyncSequence where Base : AsyncSequence
extension ReplaceErrorAsyncSequence: AsyncIteratorProtocol
An async sequence that replaces any errors in the sequence with a provided element.
let sequence = Fail<Int, TestError>(
error: TestError()
)
.replaceError(with: 0)
for await value in stream {
print(value)
}
// Prints:
// 0
-
The kind of elements streamed.
Declaration
Swift
public typealias Element = Base.Element
-
Creates an async sequence that replaces any errors in the sequence with a provided element.
Declaration
Swift
public init(base: Base, output: Element)
Parameters
base
The async sequence in which this sequence receives it’s elements.
output
The element with which to replace errors from the base async sequence.
-
Creates an async iterator that emits elements of this async sequence.
Declaration
Swift
public func makeAsyncIterator() -> ReplaceErrorAsyncSequence<Base>
Return Value
An instance that conforms to
AsyncIteratorProtocol
.