Generic Structure

Just

A publisher that emits an output to each subscriber just once, and then finishes.

Declaration

struct Just<Output>

Overview

You can use a Just publisher to start a chain of publishers. A Just publisher is also useful when replacing a value with Publishers.Catch.

In contrast with Result.Publisher, a Just publisher can’t fail with an error. And unlike Optional.Publisher, a Just publisher always produces a value.

Topics

Creating a Just Publisher

init(Output)

Initializes a publisher that emits the specified output just once.

Instance Properties

let output: Output

The one element that the publisher emits.

Instance Methods

func assertNoFailure(String, file: StaticString, line: UInt) -> Publishers.AssertNoFailure<Just<Output>>

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

func breakpointOnError() -> Publishers.Breakpoint<Just<Output>>

Raises a debugger signal upon receiving a failure.

func `catch`<P>((Never) -> P) -> Publishers.Catch<Just<Output>, P>

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

func collect(Int) -> Publishers.CollectByCount<Just<Output>>

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

func combineLatest<P>(P) -> Publishers.CombineLatest<Just<Output>, P>

Subscribes to an additional publisher and publishes a tuple upon receiving output from either publisher.

func combineLatest<P, Q>(P, Q) -> Publishers.CombineLatest3<Just<Output>, P, Q>

Subscribes to two additional publishers and publishes a tuple upon receiving output from any of the publishers.

func combineLatest<P, T>(P, (Output, P.Output) -> T) -> Publishers.Map<Publishers.CombineLatest<Just<Output>, P>, T>

Subscribes to an additional publisher and invokes a closure upon receiving output from either publisher.

func combineLatest<P, Q, R>(P, Q, R) -> Publishers.CombineLatest4<Just<Output>, P, Q, R>

Subscribes to three additional publishers and publishes a tuple upon receiving output from any of the publishers.

func combineLatest<P, Q, T>(P, Q, (Output, P.Output, Q.Output) -> T) -> Publishers.Map<Publishers.CombineLatest3<Just<Output>, P, Q>, T>

Subscribes to two additional publishers and invokes a closure upon receiving output from any of the publishers.

func combineLatest<P, Q, R, T>(P, Q, R, (Output, P.Output, Q.Output, R.Output) -> T) -> Publishers.Map<Publishers.CombineLatest4<Just<Output>, P, Q, R>, T>

Subscribes to three additional publishers and invokes a closure upon receiving output from any of the publishers.

func compactMap<T>((Output) -> T?) -> Publishers.CompactMap<Just<Output>, T>

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

func contains(Output) -> Just<Bool>
func contains(Output) -> Publishers.Contains<Just<Output>>

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

func delay<S>(for: S.SchedulerTimeType.Stride, tolerance: S.SchedulerTimeType.Stride?, scheduler: S, options: S.SchedulerOptions?) -> Publishers.Delay<Just<Output>, S>

Delays delivery of all output to the downstream receiver by a specified amount of time on a particular scheduler.

func drop<P>(untilOutputFrom: P) -> Publishers.DropUntilOutput<Just<Output>, P>

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

func encode<Coder>(encoder: Coder) -> Publishers.Encode<Just<Output>, Coder>

Encodes the output from upstream using a specified encoder.

func eraseToAnyPublisher() -> AnyPublisher<Output, Never>

Wraps this publisher with a type eraser.

func flatMap<T, P>(maxPublishers: Subscribers.Demand, (Output) -> P) -> Publishers.FlatMap<P, Just<Output>>

Transforms all elements from an upstream publisher into a new or existing publisher.

func makeConnectable() -> Publishers.MakeConnectable<Just<Output>>

Creates a connectable wrapper around the publisher.

func map<T>((Output) -> T) -> Publishers.Map<Just<Output>, T>

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

func mapError<E>((Never) -> E) -> Publishers.MapError<Just<Output>, E>

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

func max() -> Just<Output>
func max() -> Publishers.Comparison<Just<Output>>

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

func measureInterval<S>(using: S, options: S.SchedulerOptions?) -> Publishers.MeasureInterval<Just<Output>, S>

Measures and emits the time interval between events received from an upstream publisher.

func merge(with: Just<Output>) -> Publishers.MergeMany<Just<Output>>

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<Just<Output>, 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<Just<Output>, 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<Just<Output>, 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<Just<Output>, 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<Just<Output>, 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<Just<Output>, 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() -> Just<Output>
func min() -> Publishers.Comparison<Just<Output>>

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

func multicast<S>(() -> S) -> Publishers.Multicast<Just<Output>, S>

Applies a closure to create a subject that delivers elements to subscribers.

func multicast<S>(subject: S) -> Publishers.Multicast<Just<Output>, S>

Provides a subject to deliver elements to multiple subscribers.

func output<R>(in: R) -> Publishers.Output<Just<Output>>

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

func prefix<P>(untilOutputFrom: P) -> Publishers.PrefixUntilOutput<Just<Output>, P>

Republishes elements until another publisher emits an element.

func receive<S>(on: S, options: S.SchedulerOptions?) -> Publishers.ReceiveOn<Just<Output>, S>

Specifies the scheduler on which to receive elements from the publisher.

func reduce<T>(T, (T, Output) -> T) -> Publishers.Reduce<Just<Output>, T>

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

func removeDuplicates() -> Just<Output>
func removeDuplicates() -> Publishers.RemoveDuplicates<Just<Output>>

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

func replaceNil<T>(with: T) -> Publishers.Map<Just<Output>, T>

Replaces nil elements in the stream with the provided element.

func scan<T>(T, (T, Output) -> T) -> Publishers.Scan<Just<Output>, 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<Just<Output>, E>

Changes the failure type declared by the upstream publisher.

func share() -> Publishers.Share<Just<Output>>

Returns a publisher as a class instance.

func sink(receiveValue: ((Output) -> Void)) -> AnyCancellable

Attaches a subscriber with closure-based behavior to a publisher that never fails.

func subscribe<S>(S) -> AnyCancellable

Attaches the specified subject to this publisher.

func subscribe<S>(S)

Attaches the specified subscriber to this publisher.

func subscribe<S>(on: S, options: S.SchedulerOptions?) -> Publishers.SubscribeOn<Just<Output>, S>

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

func switchToLatest() -> Publishers.SwitchToLatest<Output, Just<Output>>

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<Just<Output>, S>

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

func timeout<S>(S.SchedulerTimeType.Stride, scheduler: S, options: S.SchedulerOptions?, customError: (() -> Never)?) -> Publishers.Timeout<Just<Output>, S>

Terminates publishing if the upstream publisher exceeds the specified time interval without producing an element.

func tryCatch<P>((Never) -> P) -> Publishers.TryCatch<Just<Output>, P>

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

func tryCompactMap<T>((Output) -> T?) -> Publishers.TryCompactMap<Just<Output>, T>

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

func tryDrop(while: (Output) -> Bool) -> Publishers.TryDropWhile<Just<Output>>

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

func tryFilter((Output) -> Bool) -> Publishers.TryFilter<Just<Output>>

Republishes all elements that match a provided error-throwing closure.

func tryFirst(where: (Output) -> Bool) -> Publishers.TryFirstWhere<Just<Output>>

Publishes the first element of a stream to satisfy a throwing predicate closure, then finishes.

func tryLast(where: (Output) -> Bool) -> Publishers.TryLastWhere<Just<Output>>

Publishes only the last element of a stream that satisfies an error-throwing predicate closure, after the stream finishes.

func tryMap<T>((Output) -> T) -> Publishers.TryMap<Just<Output>, T>

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

func tryMax(by: (Output, Output) -> Bool) -> Publishers.TryComparison<Just<Output>>

Publishes the maximum value received from the upstream publisher, using the provided error-throwing closure to order the items.

func tryMin(by: (Output, Output) -> Bool) -> Publishers.TryComparison<Just<Output>>

Publishes the minimum value received from the upstream publisher, using the provided error-throwing closure to order the items.

func tryPrefix(while: (Output) -> Bool) -> Publishers.TryPrefixWhile<Just<Output>>

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

func tryReduce<T>(T, (T, Output) -> T) -> Publishers.TryReduce<Just<Output>, 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, Output) -> T) -> Publishers.TryScan<Just<Output>, 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<Just<Output>, P>

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

func zip<P, T>(P, (Output, P.Output) -> T) -> Publishers.Map<Publishers.Zip<Just<Output>, P>, T>

Combines elements from another publisher and delivers a transformed output.

func zip<P, Q>(P, Q) -> Publishers.Zip3<Just<Output>, P, Q>

Combines elements from two other publishers and delivers groups of elements as tuples.

func zip<P, Q, T>(P, Q, (Output, P.Output, Q.Output) -> T) -> Publishers.Map<Publishers.Zip3<Just<Output>, P, Q>, T>

Combines elements from two other publishers and delivers a transformed output.

func zip<P, Q, R>(P, Q, R) -> Publishers.Zip4<Just<Output>, P, Q, R>

Combines elements from three other publishers and delivers groups of elements as tuples.

Relationships

Conforms To

See Also

Convenience Publishers

class Future

A publisher that eventually produces a single value and then finishes or fails.

struct Deferred

A publisher that awaits subscription before running the supplied closure to create a publisher for the new subscriber.

struct Empty

A publisher that never publishes any values, and optionally finishes immediately.

struct Fail

A publisher that immediately terminates with the specified error.

struct Record

A publisher that allows for recording a series of inputs and a completion, for later playback to each subscriber.