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

Initialization

  • 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.

AsyncSequence

  • 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.

AsyncIteratorProtocol

  • next() Asynchronous

    Produces the next element in the sequence.

    Declaration

    Swift

    public mutating func next() async -> Element?

    Return Value

    The next element or nil if the end of the sequence is reached.