Guarantee

public final class Guarantee<T> : Thenable

A Guarantee is a functional abstraction around an asynchronous operation that cannot error.

See

Thenable
  • Returns a Guarantee sealed with the provided value.

    Declaration

    Swift

    public static func value(_ value: T) -> Guarantee<T>
  • Returns a pending Guarantee that can be resolved with the provided closure’s parameter.

    Declaration

    Swift

    public init(resolver body: (@escaping (T) -> Void) -> Void)
  • Returns a pending Guarantee that can be resolved with the provided closure’s parameter.

    Declaration

    Swift

    public convenience init(cancellable: Cancellable, resolver body: (@escaping (T) -> Void) -> Void)
  • See

    Thenable.pipe

    Declaration

    Swift

    public func pipe(to: @escaping (Result<T, Error>) -> Void)
  • Declaration

    Swift

    public var result: Result<T, Error>? { get }
  • Returns a tuple of a pending Guarantee and a function that resolves it.

    Declaration

    Swift

    public class func pending() -> (guarantee: Guarantee<T>, resolve: (T) -> Void)
  • Undocumented

    Declaration

    Swift

    public func setCancellable(_ cancellable: Cancellable)
  • Undocumented

    Declaration

    Swift

    @discardableResult
    func done(on: Dispatcher = conf.D.return, _ body: @escaping (T) -> Void) -> Guarantee<Void>
  • Undocumented

    Declaration

    Swift

    func get(on: Dispatcher = conf.D.return, _ body: @escaping (T) -> Void) -> Guarantee<T>
  • Undocumented

    Declaration

    Swift

    func map<U>(on: Dispatcher = conf.D.map, _ body: @escaping (T) -> U) -> Guarantee<U>
  • Undocumented

    Declaration

    Swift

    @discardableResult
    func then<U>(on: Dispatcher = conf.D.map, _ body: @escaping (T) -> Guarantee<U>) -> Guarantee<U>
  • Undocumented

    Declaration

    Swift

    func asVoid() -> Guarantee<Void>
  • Blocks this thread, so you know, don’t call this on a serial thread that any part of your chain may use. Like the main thread for example.

    Declaration

    Swift

    func wait() -> T
  • Undocumented

    Declaration

    Swift

    @discardableResult
    func then<U>(on: DispatchQueue? = .pmkDefault, flags: DispatchWorkItemFlags? = nil, _ body: @escaping (T) -> Guarantee<U>) -> Guarantee<U>
  • Undocumented

    Declaration

    Swift

    @discardableResult
    func then<U>(on: DispatchQueue? = .pmkDefault, flags: DispatchWorkItemFlags? = nil, _ body: @escaping (T) throws -> Guarantee<U>) -> Promise<U>
  • Undocumented

    Declaration

    Swift

    func map<U>(on: DispatchQueue? = .pmkDefault, flags: DispatchWorkItemFlags? = nil, _ body: @escaping (T) -> U) -> Guarantee<U>
  • Undocumented

    Declaration

    Swift

    func map<U>(on: DispatchQueue? = .pmkDefault, flags: DispatchWorkItemFlags? = nil, _ body: @escaping (T) throws -> U) -> Promise<U>
  • Undocumented

    Declaration

    Swift

    @discardableResult
    func done(on: DispatchQueue? = .pmkDefault, flags: DispatchWorkItemFlags? = nil, _ body: @escaping (T) -> Void) -> Guarantee<Void>
  • Undocumented

    Declaration

    Swift

    @discardableResult
    func done(on: DispatchQueue? = .pmkDefault, flags: DispatchWorkItemFlags? = nil, _ body: @escaping (T) throws -> Void) -> Promise<Void>
  • Undocumented

    Declaration

    Swift

    func get(on: DispatchQueue? = .pmkDefault, flags: DispatchWorkItemFlags? = nil, _ body: @escaping (T) -> Void) -> Guarantee<T>
  • Undocumented

    Declaration

    Swift

    func get(on: DispatchQueue? = .pmkDefault, flags: DispatchWorkItemFlags? = nil, _ body: @escaping (T) throws -> Void) -> Promise<T>

Available where T: Sequence

  • Guarantee<[T]> => T -> U => Guarantee<[U]>

    Guarantee.value([1,2,3])
       .mapValues { integer in integer * 2 }
       .done {
           // $0 => [2,4,6]
       }
    

    Declaration

    Swift

    func mapValues<U>(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ transform: @escaping (T.Iterator.Element) -> U) -> Guarantee<[U]>
  • Guarantee<[T]> => T -> [U] => Guarantee<[U]>

    Guarantee.value([1,2,3])
       .flatMapValues { integer in [integer, integer] }
       .done {
           // $0 => [1,1,2,2,3,3]
       }
    

    Declaration

    Swift

    func flatMapValues<U>(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ transform: @escaping (T.Iterator.Element) -> U) -> Guarantee<[U.Iterator.Element]> where U : Sequence
  • Guarantee<[T]> => T -> U? => Guarantee<[U]>

    Guarantee.value(["1","2","a","3"])
       .compactMapValues { Int($0) }
       .done {
           // $0 => [1,2,3]
       }
    

    Declaration

    Swift

    func compactMapValues<U>(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ transform: @escaping (T.Iterator.Element) -> U?) -> Guarantee<[U]>
  • Guarantee<[T]> => T -> Guarantee<U> => Guarantee<[U]>

    Guarantee.value([1,2,3])
       .thenMap { .value($0 * 2) }
       .done {
           // $0 => [2,4,6]
       }
    

    Declaration

    Swift

    func thenMap<U>(on: Dispatcher = conf.D.map, _ transform: @escaping (T.Iterator.Element) -> Guarantee<U>) -> Guarantee<[U]>
  • Guarantee<[T]> => T -> Guarantee<[U]> => Guarantee<[U]>

    Guarantee.value([1,2,3])
       .thenFlatMap { integer in .value([integer, integer]) }
       .done {
           // $0 => [1,1,2,2,3,3]
       }
    

    Declaration

    Swift

    func thenFlatMap<U>(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ transform: @escaping (T.Iterator.Element) -> U) -> Guarantee<[U.T.Iterator.Element]> where U : Thenable, U.T : Sequence
  • Guarantee<[T]> => T -> Bool => Guarantee<[T]>

    Guarantee.value([1,2,3])
       .filterValues { $0 > 1 }
       .done {
           // $0 => [2,3]
       }
    

    Declaration

    Swift

    func filterValues(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ isIncluded: @escaping (T.Iterator.Element) -> Bool) -> Guarantee<[T.Iterator.Element]>
  • Guarantee<[T]> => (T, T) -> Bool => Guarantee<[T]>

    Guarantee.value([5,2,3,4,1]) .sortedValues { $0 > $1 } .done { // $0 => [5,4,3,2,1] }

    Declaration

    Swift

    func sortedValues(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ areInIncreasingOrder: @escaping (T.Iterator.Element, T.Iterator.Element) -> Bool) -> Guarantee<[T.Iterator.Element]>

Available where T: Sequence, T.Iterator.Element: Comparable

  • Guarantee<[T]> => Guarantee<[T]>

    Guarantee.value([5,2,3,4,1]) .sortedValues() .done { // $0 => [1,2,3,4,5] }

    Declaration

    Swift

    func sortedValues(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil) -> Guarantee<[T.Iterator.Element]>

Available where T == Void

  • Undocumented

    Declaration

    Swift

    convenience init()
  • Undocumented

    Declaration

    Swift

    static var value: Guarantee<Void> { get }
  • Undocumented

    Declaration

    Swift

    convenience init(resolver body: (@escaping () -> Void) -> Void)

Available where T: Sequence

  • Undocumented

    Declaration

    Swift

    func thenMap<U>(on: DispatchQueue? = .pmkDefault, flags: DispatchWorkItemFlags? = nil, _ transform: @escaping (T.Iterator.Element) -> Guarantee<U>) -> Guarantee<[U]>