ReplayLastSubjectType
public struct ReplayLastSubjectType<Element, ErrorType> where ErrorType : Error
Abstraction over subject types able to keep the last object (CurrentValueSubject
, BehaviorSubject
, MutableProperty
, Variable
) from
reactive frameworks.
This abstraction uses concept similar to type-erasure or protocol witness pattern, wrapping the behaviour of concrete implementations and
delegating to them once the wrapper funcions are called.
-
Upstream publisher that feeds data into this subject
Declaration
Swift
public let publisher: PublisherType<Element, ErrorType>
-
Downstream subscriber that subscribes to this subject and will receive events from it
Declaration
Swift
public let subscriber: SubscriberType<Element, ErrorType>
-
Reads the most recent element emitted by this subject. This subject can be seen as a variable in stateful programming style, it holds one value that can be read at any point using a getter function
() -> Element
. Useful for bridging with the imperative world.Declaration
Swift
public var value: () -> Element
-
Creates an abstraction over subject types able to keep the last object (
CurrentValueSubject
,BehaviorSubject
,MutableProperty
,Variable
) from reactive frameworks.Declaration
Swift
public init( publisher: PublisherType<Element, ErrorType>, subscriber: SubscriberType<Element, ErrorType>, value: @escaping () -> Element)
Parameters
publisher
Upstream publisher that feeds events into this subject
subscriber
Downstream subscriber that subscribes to this subject and will receive events from it
value
Reads the most recent element emitted by this subject. This subject can be seen as a variable in stateful programming style, it holds one value that can be read at any point using a getter function
() -> Element
. Useful for bridging with the imperative world. -
Atomically mutate this subject’s value in a closure where you can read and write the current element value
Declaration
Swift
@discardableResult public func mutate<Result>(_ action: (inout Element) -> Result) -> Result
Parameters
action
read and write the current value atomically, and optionally return something
Return Value
returns whatever is returned by the action closure, allowing to chain operations
-
Atomically mutate this subject’s value in a closure where you can read and write the current element value Before the mutation, a condition will be evaluated and the mutation will only happen when the result of this evaluation returns
true
. This allows you to simulate the mutation before executing it.Declaration
Swift
@discardableResult public func mutate<Result>(when condition: @escaping (Result) -> Bool, action: (inout Element) -> Result) -> Result
Parameters
condition
a predicate that, after simulating the mutation, allows you to decide if it should happen or not
action
read and write the current value atomically, and optionally return something
Return Value
returns whatever is returned by the action closure, allowing to chain operations