ResultPromise
public class ResultPromise<T, E> where E : Error
ResultPromise is a minimal Promise implementation that wraps a
Result<T, E> instance. It supports the fulfil, await, then and
thenAsync combinators, facilitating a fluid sequencing of computations that
produce either a Result (then) or a ResultPromise instance (thenAsync).
(The reject combinator is redundant, as failure is handled by the embedded
Result.)
-
Fulfil this promise with
result.Declaration
Swift
public func fulfil(with result: Result<T, E>)Parameters
resultA
Result<T, E>that describes the result. -
Execute the
observerclosure when the promise is fulfilled.Declaration
Swift
public func await(with observer: @escaping (Result<T, E>) -> Void)Parameters
observerA closure that takes a
Resultinstance and returns nothing. -
Produce a new
ResultPromisebyflatMap‘ing the supplied function over the embeddedResult.Declaration
Swift
public func then<U>(_ f: (@escaping (T) -> Result<U, E>)) -> ResultPromise<U, E>Parameters
fA closure
(T) -> Result<U, E>.Return Value
A new
ResultPromise<U, E>instance, where the embeddedResult<U, E>is the result offlatMap‘ingfover theResult<T, E>embedded in this instance. -
Produce a new
ResultPromiseby applying the supplied function to the value contained in the embeddedResultinstance.Declaration
Swift
public func thenAsync<U>(_ f: (@escaping (T) -> ResultPromise<U, E>)) -> ResultPromise<U, E>Parameters
fA closure
(T) -> Result<U, E>.Return Value
A new
ResultPromise<U, E>instance.
View on GitHub
ResultPromise Class Reference