Contents

sideeffect-io/asyncextensions

**AsyncExtensions** provides a collection of operators that intends to ease the creation and combination of `AsyncSequences`.

Adding AsyncExtensions as a Dependency

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.

Features

Channels

  • AsyncBufferedChannel: Buffered communication channel between tasks. The elements are not shared and will be spread across consumers (same as

AsyncStream)

Subjects

Combiners

  • zip(::): Zips two AsyncSequence into an AsyncSequence of tuple of elements
  • zip(::_:): Zips three AsyncSequence into an AsyncSequence of tuple of elements
  • zip(_:): Zips any async sequences into an array of elements
  • merge(::): Merges two AsyncSequence into an AsyncSequence of elements
  • merge(::_:): Merges three AsyncSequence into an AsyncSequence of elements
  • merge(_:): Merges any AsyncSequence into an AsyncSequence of elements
  • withLatest(_:): 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 sequences

Creators

Operators

  • handleEvents(): Executes closures during the lifecycle of the self
  • mapToResult(): Maps elements and failure from self to a Result type
  • prepend(_:): Prepends an element to self
  • scan(::): Transforms elements from self by providing the current element to a closure along with the last value returned by the closure
  • assign(_:): Assigns elements from self to a property
  • collect(_:): Iterate over elements from self and execute a closure
  • eraseToAnyAsyncSequence(): Erases to AnyAsyncSequence
  • flatMapLatest(_:): 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 Subject
  • share(): Shares values from self to several consumers
  • switchToLatest(): 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.

Package Metadata

Repository: sideeffect-io/asyncextensions

Default branch: main

README: README.md