Extensions for ReactiveCocoa that may not fit in the core framework.
All Signal
operators can also be lifted toSignalProducer
.
Applies transform
to values from signal
with non-nil results unwrapped and forwared on the returned signal. This is equivalent to map { … } |> filter { $0 != nil } |> map { $0! }
but without creating extra intermediate signals.
func filterMap<T, U, E>(transform: T -> U?)(signal: Signal<T, E>) -> Signal<U, E>
Wraps a signal
in a version that drops Error
events. By default errors are replaced with a Completed
event but Interrupted
can also be specified as replacement
.
func ignoreError<T, E>(signal: Signal<T, E>) -> Signal<T, NoError>
func ignoreError<T, E>(#replacement: Event<T, NoError>)(signal: Signal<T, E>) -> Signal<T, NoError>
Forwards events from signal
until it terminates or until interval
time passes. This is nearly identical to timeoutWithError
from RAC except any terminating event
can be used for the timeout.
func timeoutAfter<T, E>(interval: NSTimeInterval, withEvent event: Event<T, E>, onScheduler scheduler: DateSchedulerType) -> Signal<T, E> -> Signal<T, E>
Flattens batches of elements sent on signal
into each individual element. The inverse of collect
.
func uncollect<S: SequenceType, E>(signal: Signal<S, E>) -> Signal<S.Generator.Element, E>
Operators specific to SignalProducer
.
Partitions values from producer
into new producer groups based on the key returned from grouping
. Termination events on the original producer are forwarded to each inner producer group.
func groupBy<K: Hashable, T, E>(grouping: T -> K)(producer: SignalProducer<T, E>)
-> SignalProducer<(K, SignalProducer<T, E>), E>
Extensions for creating properties from signals. These are curried to support chaining with |>
.
Creates a new property bound to the provided signal/producer starting with initialValue
.
func propertyOf<T>(initialValue: T)(signal: Signal<T, NoError>) -> PropertyOf<T>
func propertyOf<T>(initialValue: T)(producer: SignalProducer<T, NoError>) -> PropertyOf<T>
Wraps sink
in a property bound to the provided signal/producer. Values sent on signal
are put
into the sink
to update it.
func propertySink<S: SinkType>(sink: S)(signal: Signal<S.Element, NoError>) -> PropertyOf<S>
func propertySink<S: SinkType>(sink: S)(producer: SignalProducer<S.Element, NoError>) -> PropertyOf<S>
Rex is released under the MIT license