Generic Structure

Publishers.Sequence

A publisher that publishes a given sequence of elements.

Declaration

struct Sequence<Elements, Failure> where Elements : Sequence, Failure : Error

Overview

When the publisher exhausts the elements in the sequence, the next request causes the publisher to finish.

Topics

Initializers

init(sequence: Elements)

Creates a publisher for a sequence of elements.

Instance Properties

let sequence: Elements

The sequence of elements to publish.

Instance Methods

func assertNoFailure(String, file: StaticString, line: UInt) -> Publishers.AssertNoFailure<Publishers.Sequence<Elements, Failure>>

Raises a fatal error when its upstream publisher fails, and otherwise republishes all received input.

func assign<Root>(to: ReferenceWritableKeyPath<Root, Elements.Element>, on: Root) -> AnyCancellable

Assigns the value of a KVO-compliant property from a publisher.

func `catch`<P>((Failure) -> P) -> Publishers.Catch<Publishers.Sequence<Elements, Failure>, P>

Handles errors from an upstream publisher by replacing it with another publisher.

func collect(Int) -> Publishers.CollectByCount<Publishers.Sequence<Elements, Failure>>

Collects up to the specified number of elements, and then emits a single array of the collection.

func compactMap<T>((Elements.Element) -> T?) -> Publishers.CompactMap<Publishers.Sequence<Elements, Failure>, T>

Calls a closure with each received element and publishes any returned optional that has a value.

func contains(Elements.Element) -> Publishers.Contains<Publishers.Sequence<Elements, Failure>>

Publishes a Boolean value upon receiving an element equal to the argument.

func contains(Elements.Element) -> Result<Bool, Failure>.Publisher
func count() -> Publishers.Count<Publishers.Sequence<Elements, Failure>>

Publishes the number of elements received from the upstream publisher.

func count() -> Result<Int, Failure>.Publisher
func decode<Item, Coder>(type: Item.Type, decoder: Coder) -> Publishers.Decode<Publishers.Sequence<Elements, Failure>, Item, Coder>

Decodes the output from upstream using a specified TopLevelDecoder. For example, use JSONDecoder.

func drop<P>(untilOutputFrom: P) -> Publishers.DropUntilOutput<Publishers.Sequence<Elements, Failure>, P>

Ignores elements from the upstream publisher until it receives an element from a second publisher.

func encode<Coder>(encoder: Coder) -> Publishers.Encode<Publishers.Sequence<Elements, Failure>, Coder>

Encodes the output from upstream using a specified TopLevelEncoder. For example, use JSONEncoder.

func first() -> Publishers.First<Publishers.Sequence<Elements, Failure>>

Publishes the first element of a stream, then finishes.

func last() -> Publishers.Last<Publishers.Sequence<Elements, Failure>>

Only publishes the last element of a stream, after the stream finishes.

func last(where: (Elements.Element) -> Bool) -> Publishers.LastWhere<Publishers.Sequence<Elements, Failure>>

Only publishes the last element of a stream that satisfies a predicate closure, after the stream finishes.

func makeConnectable() -> Publishers.MakeConnectable<Publishers.Sequence<Elements, Failure>>

Creates a connectable wrapper around the publisher.

func map<T>((Elements.Element) -> T) -> Publishers.Map<Publishers.Sequence<Elements, Failure>, T>

Transforms all elements from the upstream publisher with a provided closure.

func mapError<E>((Failure) -> E) -> Publishers.MapError<Publishers.Sequence<Elements, Failure>, E>

Converts any failure from the upstream publisher into a new error.

func max() -> Publishers.Comparison<Publishers.Sequence<Elements, Failure>>

Publishes the maximum value received from the upstream publisher, after it finishes.

func max() -> Optional<Publishers.Sequence<Elements, Failure>.Output>.Publisher
func merge(with: Publishers.Sequence<Elements, Failure>) -> Publishers.MergeMany<Publishers.Sequence<Elements, Failure>>

Combines elements from this publisher with those from another publisher of the same type, delivering an interleaved sequence of elements.

func merge<B, C>(with: B, C) -> Publishers.Merge3<Publishers.Sequence<Elements, Failure>, B, C>

Combines elements from this publisher with those from two other publishers, delivering an interleaved sequence of elements.

func merge<B, C, D>(with: B, C, D) -> Publishers.Merge4<Publishers.Sequence<Elements, Failure>, B, C, D>

Combines elements from this publisher with those from three other publishers, delivering an interleaved sequence of elements.

func merge<B, C, D, E>(with: B, C, D, E) -> Publishers.Merge5<Publishers.Sequence<Elements, Failure>, B, C, D, E>

Combines elements from this publisher with those from four other publishers, delivering an interleaved sequence of elements.

func merge<B, C, D, E, F>(with: B, C, D, E, F) -> Publishers.Merge6<Publishers.Sequence<Elements, Failure>, B, C, D, E, F>

Combines elements from this publisher with those from five other publishers, delivering an interleaved sequence of elements.

func merge<B, C, D, E, F, G>(with: B, C, D, E, F, G) -> Publishers.Merge7<Publishers.Sequence<Elements, Failure>, B, C, D, E, F, G>

Combines elements from this publisher with those from six other publishers, delivering an interleaved sequence of elements.

func merge<B, C, D, E, F, G, H>(with: B, C, D, E, F, G, H) -> Publishers.Merge8<Publishers.Sequence<Elements, Failure>, B, C, D, E, F, G, H>

Combines elements from this publisher with those from seven other publishers, delivering an interleaved sequence of elements.

func min() -> Publishers.Comparison<Publishers.Sequence<Elements, Failure>>

Publishes the minimum value received from the upstream publisher, after it finishes.

func min() -> Optional<Publishers.Sequence<Elements, Failure>.Output>.Publisher
func output(at: Int) -> Publishers.Output<Publishers.Sequence<Elements, Failure>>

Publishes a specific element, indicated by its index in the sequence of published elements.

func output<R>(in: R) -> Publishers.Output<Publishers.Sequence<Elements, Failure>>

Publishes elements specified by their range in the sequence of published elements.

func reduce<T>(T, (T, Elements.Element) -> T) -> Publishers.Reduce<Publishers.Sequence<Elements, Failure>, T>

Applies a closure that accumulates each element of a stream and publishes a final result upon completion.

func removeDuplicates() -> Publishers.RemoveDuplicates<Publishers.Sequence<Elements, Failure>>

Publishes only elements that don’t match the previous element.

func replaceNil<T>(with: T) -> Publishers.Map<Publishers.Sequence<Elements, Failure>, T>

Replaces nil elements in the stream with the proviced element.

func retry(Int) -> Publishers.Retry<Publishers.Sequence<Elements, Failure>>

Attempts to recreate a failed subscription with the upstream publisher using a specified number of attempts to establish the connection.

func scan<T>(T, (T, Elements.Element) -> T) -> Publishers.Scan<Publishers.Sequence<Elements, Failure>, T>

Transforms elements from the upstream publisher by providing the current element to a closure along with the last value returned by the closure.

func setFailureType<E>(to: E.Type) -> Publishers.SetFailureType<Publishers.Sequence<Elements, Failure>, E>

Changes the failure type declared by the upstream publisher.

func subscribe<S>(S) -> AnyCancellable

Attaches the specified Subscriber to this Publisher.

func subscribe<S>(S)

Attaches the specified subscriber to this publisher.

func subscribe<S>(on: S, options: S.SchedulerOptions?) -> Publishers.SubscribeOn<Publishers.Sequence<Elements, Failure>, S>

Specifies the scheduler on which to perform subscribe, cancel, and request operations.

func switchToLatest() -> Publishers.SwitchToLatest<Elements.Element, Publishers.Sequence<Elements, Failure>>

Flattens the stream of events from multiple upstream publishers to appear as if they were coming from a single stream of events.

func throttle<S>(for: S.SchedulerTimeType.Stride, scheduler: S, latest: Bool) -> Publishers.Throttle<Publishers.Sequence<Elements, Failure>, S>

Publishes either the most-recent or first element published by the upstream publisher in the specified time interval.

func tryCompactMap<T>((Elements.Element) -> T?) -> Publishers.TryCompactMap<Publishers.Sequence<Elements, Failure>, T>

Calls an error-throwing closure with each received element and publishes any returned optional that has a value.

func tryDrop(while: (Elements.Element) -> Bool) -> Publishers.TryDropWhile<Publishers.Sequence<Elements, Failure>>

Omits elements from the upstream publisher until an error-throwing closure returns false, before republishing all remaining elements.

func tryLast(where: (Elements.Element) -> Bool) -> Publishers.TryLastWhere<Publishers.Sequence<Elements, Failure>>

Only publishes the last element of a stream that satisfies a error-throwing predicate closure, after the stream finishes.

func tryMap<T>((Elements.Element) -> T) -> Publishers.TryMap<Publishers.Sequence<Elements, Failure>, T>

Transforms all elements from the upstream publisher with a provided error-throwing closure.

func tryPrefix(while: (Elements.Element) -> Bool) -> Publishers.TryPrefixWhile<Publishers.Sequence<Elements, Failure>>

Republishes elements while a error-throwing predicate closure indicates publishing should continue.

func tryReduce<T>(T, (T, Elements.Element) -> T) -> Publishers.TryReduce<Publishers.Sequence<Elements, Failure>, T>

Applies an error-throwing closure that accumulates each element of a stream and publishes a final result upon completion.

func tryScan<T>(T, (T, Elements.Element) -> T) -> Publishers.TryScan<Publishers.Sequence<Elements, Failure>, T>

Transforms elements from the upstream publisher by providing the current element to an error-throwing closure along with the last value returned by the closure.

func zip<P>(P) -> Publishers.Zip<Publishers.Sequence<Elements, Failure>, P>

Combine elements from another publisher and deliver pairs of elements as tuples.

func zip<P, Q>(P, Q) -> Publishers.Zip3<Publishers.Sequence<Elements, Failure>, P, Q>

Combine elements from two other publishers and deliver groups of elements as tuples.

func zip<P, Q, R>(P, Q, R) -> Publishers.Zip4<Publishers.Sequence<Elements, Failure>, P, Q, R>

Combine elements from three other publishers and deliver groups of elements as tuples.

Relationships

Conforms To

See Also

Convenience Publishers

struct Publishers.Catch

A publisher that handles errors from an upstream publisher by replacing the failed publisher with another publisher.