AsyncExtensions aims to mimic Swift Combine operators for async sequences.
AsyncExtensions provides a collection of operators that intends to ease the creation and combination of AsyncSequences
.
AsyncExtensions can be seen as a companion to Apple swift-async-algorithms. For now there is an overlap between both libraries, but when swift-async-algorithms becomes stable the overlapping operators while be deprecated in AsyncExtensions. Nevertheless AsyncExtensions will continue to provide the operators that the community needs and are not provided by Apple.
To use the AsyncExtensions
library in a SwiftPM project,
add the following line to the dependencies in your Package.swift
file:
.package(url: "https://github.com/sideeffect-io/AsyncExtensions"),
Include "AsyncExtensions"
as a dependency for your executable target:
.target(name: "<target>", dependencies: ["AsyncExtensions"]),
Finally, add import AsyncExtensions
to your source code.
zip(_:_:)
: Zips two AsyncSequence
into an AsyncSequence of tuple of elementszip(_:_:_:)
: Zips three AsyncSequence
into an AsyncSequence of tuple of elementszip(_:)
: Zips any async sequences into an array of elementsmerge(_:_:)
: Merges two AsyncSequence
into an AsyncSequence of elementsmerge(_:_:_:)
: Merges three AsyncSequence
into an AsyncSequence of elementsmerge(_:)
: Merges any AsyncSequence
into an AsyncSequence of elementswithLatest(_:)
: Combines elements from self with the last known element from an other AsyncSequence
withLatest(_:_:)
: Combines elements from self with the last known elements from two other async sequencesAsyncSequence
that immediately finishesAsyncSequence
that immediately failsAsyncSequence
that emits an element an finishesAsyncSequence
that emits an elements and finishes bases on a throwing closureAsyncSequence
of the elements from the base sequenceAsyncSequence
that emits a date value periodicallyhandleEvents()
: Executes closures during the lifecycle of the selfmapToResult()
: Maps elements and failure from self to a Result
typeprepend(_:)
: Prepends an element to selfscan(_:_:)
: Transforms elements from self by providing the current element to a closure along with the last value returned by the closureassign(_:)
: Assigns elements from self to a propertycollect(_:)
: Iterate over elements from self and execute a closureeraseToAnyAsyncSequence()
: Erases to AnyAsyncSequenceflatMapLatest(_:)
: Transforms elements from self into a AsyncSequence
and republishes elements sent by the most recently received AsyncSequence
when self is an AsyncSequence
of AsyncSequence
multicast(_:)
: Shares values from self to several consumers thanks to a provided Subjectshare()
: Shares values from self to several consumersswitchToLatest()
: Republishes elements sent by the most recently received AsyncSequence
when self is an AsyncSequence
of AsyncSequence
More operators and extensions are to come. Pull requests are of course welcome.