Applicative

public protocol Applicative : Functor

An Applicative Functor is a Functor that also provides functionality to lift pure expressions, and sequence computations and combine their results.

Instances of this typeclass must obey the following laws:

  1. Identity

    ap(pure(id), v) == v
    
  2. Composition

    ap(ap(ap(pure(compose), u), v), w) == compose(u, compose(v, w))
    
  3. Homomorphism

    ap(pure(f), pure(x)) == pure(f(x))
    
  4. Interchange

    ap(fa, pure(b)) == ap(pure({ x in x(a) }), fa)
    
  • Lifts a value to the context type implementing this instance of Applicative.

    Declaration

    Swift

    static func pure<A>(_ a: A) -> Kind<Self, A>

    Parameters

    a

    Value to be lifted.

    Return Value

    Provided value in the context type implementing this instance.

  • Sequential application.

    Declaration

    Swift

    static func ap<A, B>(_ ff: Kind<Self, (A) -> B>, _ fa: Kind<Self, A>) -> Kind<Self, B>

    Parameters

    ff

    A function in the context implementing this instance.

    fa

    A value in the context implementing this instance.

    Return Value

    A value in the context implementing this instance, resulting of the transformation of the contained original value with the contained function.

  • sequenceRight(_:_:) Extension method

    Sequentially compose two computations, discarding the value produced by the first.

    Declaration

    Swift

    static func sequenceRight<A, B>(_ fa: Kind<Self, A>, _ fb: Kind<Self, B>) -> Kind<Self, B>

    Parameters

    fa

    1st computation.

    fb

    2nd computation.

    Return Value

    Result of running the second computation after the first one.

  • sequenceLeft(_:_:) Extension method

    Sequentially compose two computations, discarding the value produced by the second.

    Declaration

    Swift

    static func sequenceLeft<A, B>(_ fa: Kind<Self, A>, _ fb: Kind<Self, B>) -> Kind<Self, A>

    Parameters

    fa

    1st computation.

    fb

    2nd computation.

    Return Value

    Result produced from the first computation after both are computed.

  • product(_:_:) Extension method

    Creates a tuple in the context implementing this instance from two values in the same context.

    Declaration

    Swift

    static func product<A, B>(_ fa: Kind<Self, A>, _ fb: Kind<Self, B>) -> Kind<Self, (A, B)>

    Parameters

    fa

    1st value for the tuple.

    fb

    2nd value for the tuple.

    Return Value

    A tuple of the provided values in the context implementing this instance.

  • product(_:_:) Extension method

    Adds an element to the right of a tuple in the context implementing this instance.

    Declaration

    Swift

    static func product<A, B, Z>(_ fa: Kind<Self, (A, B)>, _ fz: Kind<Self, Z>) -> Kind<Self, (A, B, Z)>

    Parameters

    fa

    A tuple of two elements in the context implementing this instance.

    fz

    A value in the context implementing this instance.

    Return Value

    A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.

  • product(_:_:) Extension method

    Adds an element to the right of a tuple in the context implementing this instance.

    Declaration

    Swift

    static func product<A, B, C, Z>(_ fa: Kind<Self, (A, B, C)>, _ fz: Kind<Self, Z>) -> Kind<Self, (A, B, C, Z)>

    Parameters

    fa

    A tuple of three elements in the context implementing this instance.

    fz

    A value in the context implementing this instance.

    Return Value

    A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.

  • product(_:_:) Extension method

    Adds an element to the right of a tuple in the context implementing this instance.

    Declaration

    Swift

    static func product<A, B, C, D, Z>(_ fa: Kind<Self, (A, B, C, D)>, _ fz: Kind<Self, Z>) -> Kind<Self, (A, B, C, D, Z)>

    Parameters

    fa

    A tuple of four elements in the context implementing this instance.

    fz

    A value in the context implementing this instance.

    Return Value

    A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.

  • product(_:_:) Extension method

    Adds an element to the right of a tuple in the context implementing this instance.

    Declaration

    Swift

    static func product<A, B, C, D, E, Z>(_ fa: Kind<Self, (A, B, C, D, E)>, _ fz: Kind<Self, Z>) -> Kind<Self, (A, B, C, D, E, Z)>

    Parameters

    fa

    A tuple of five elements in the context implementing this instance.

    fz

    A value in the context implementing this instance.

    Return Value

    A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.

  • product(_:_:) Extension method

    Adds an element to the right of a tuple in the context implementing this instance.

    Declaration

    Swift

    static func product<A, B, C, D, E, G, Z>(_ fa: Kind<Self, (A, B, C, D, E, G)>, _ fz: Kind<Self, Z>) -> Kind<Self, (A, B, C, D, E, G, Z)>

    Parameters

    fa

    A tuple of six elements in the context implementing this instance.

    fz

    A value in the context implementing this instance.

    Return Value

    A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.

  • product(_:_:) Extension method

    Adds an element to the right of a tuple in the context implementing this instance.

    Declaration

    Swift

    static func product<A, B, C, D, E, G, H, Z>(_ fa: Kind<Self, (A, B, C, D, E, G, H)>, _ fz: Kind<Self, Z>) -> Kind<Self, (A, B, C, D, E, G, H, Z)>

    Parameters

    fa

    A tuple of seven elements in the context implementing this instance.

    fz

    A value in the context implementing this instance.

    Return Value

    A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.

  • product(_:_:) Extension method

    Adds an element to the right of a tuple in the context implementing this instance.

    Declaration

    Swift

    static func product<A, B, C, D, E, G, H, I, Z>(_ fa: Kind<Self, (A, B, C, D, E, G, H, I)>, _ fz: Kind<Self, Z>) -> Kind<Self, (A, B, C, D, E, G, H, I, Z)>

    Parameters

    fa

    A tuple of eight elements in the context implementing this instance.

    fz

    A value in the context implementing this instance.

    Return Value

    A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.

  • map2Eval(_:_:_:) Extension method

    Performs two computations in the context implementing this instance and combines their result using the provided function.

    Declaration

    Swift

    static func map2Eval<A, B, Z>(_ fa: Kind<Self, A>, _ fb: Eval<Kind<Self, B>>, _ f: @escaping (A, B) -> Z) -> Eval<Kind<Self, Z>>

    Parameters

    fa

    A value in the context implementing this instance.

    fb

    A lazy value in the context implementing this instance.

    f

    A function to combine the result of the computations.

    Return Value

    A lazy value with the result of combining the results of each computation.

  • zip(_:_:) Extension method

    Creates a tuple out of two values in the context implementing this instance.

    Declaration

    Swift

    static func zip<A, B>(_ a: Kind<Self, A>,
                             _ b : Kind<Self, B>) -> Kind<Self, (A, B)>

    Parameters

    a

    1st value of the tuple.

    b

    2nd value of the tuple.

    Return Value

    A tuple in the context implementing this instance.

  • zip(_:_:_:) Extension method

    Creates a tuple out of three values in the context implementing this instance.

    Declaration

    Swift

    static func zip<A, B, C>(_ a: Kind<Self, A>,
                                _ b: Kind<Self, B>,
                                _ c: Kind<Self, C>) -> Kind<Self, (A, B, C)>

    Parameters

    a

    1st value of the tuple.

    b

    2nd value of the tuple.

    c

    3rd value of the tuple.

    Return Value

    A tuple in the context implementing this instance.

  • zip(_:_:_:_:) Extension method

    Creates a tuple out of four values in the context implementing this instance.

    Declaration

    Swift

    static func zip<A, B, C, D>(_ a: Kind<Self, A>,
                                   _ b: Kind<Self, B>,
                                   _ c: Kind<Self, C>,
                                   _ d: Kind<Self, D>) -> Kind<Self, (A, B, C, D)>

    Parameters

    a

    1st value of the tuple.

    b

    2nd value of the tuple.

    c

    3rd value of the tuple.

    d

    4th value of the tuple.

    Return Value

    A tuple in the context implementing this instance.

  • zip(_:_:_:_:_:) Extension method

    Creates a tuple out of five values in the context implementing this instance.

    Declaration

    Swift

    static func zip<A, B, C, D, E>(_ a: Kind<Self, A>,
                                      _ b: Kind<Self, B>,
                                      _ c: Kind<Self, C>,
                                      _ d: Kind<Self, D>,
                                      _ e: Kind<Self, E>) -> Kind<Self, (A, B, C, D, E)>

    Parameters

    a

    1st value of the tuple.

    b

    2nd value of the tuple.

    c

    3rd value of the tuple.

    d

    4th value of the tuple.

    e

    5th value of the tuple.

    Return Value

    A tuple in the context implementing this instance.

  • zip(_:_:_:_:_:_:) Extension method

    Creates a tuple out of six values in the context implementing this instance.

    Declaration

    Swift

    static func zip<A, B, C, D, E, G>(_ a: Kind<Self, A>,
                                         _ b: Kind<Self, B>,
                                         _ c: Kind<Self, C>,
                                         _ d: Kind<Self, D>,
                                         _ e: Kind<Self, E>,
                                         _ g: Kind<Self, G>) -> Kind<Self, (A, B, C, D, E, G)>

    Parameters

    a

    1st value of the tuple.

    b

    2nd value of the tuple.

    c

    3rd value of the tuple.

    d

    4th value of the tuple.

    e

    5th value of the tuple.

    g

    6th value of the tuple.

    Return Value

    A tuple in the context implementing this instance.

  • zip(_:_:_:_:_:_:_:) Extension method

    Creates a tuple out of seven values in the context implementing this instance.

    Declaration

    Swift

    static func zip<A, B, C, D, E, G, H>(_ a: Kind<Self, A>,
                                            _ b: Kind<Self, B>,
                                            _ c: Kind<Self, C>,
                                            _ d: Kind<Self, D>,
                                            _ e: Kind<Self, E>,
                                            _ g: Kind<Self, G>,
                                            _ h: Kind<Self, H>) -> Kind<Self, (A, B, C, D, E, G, H)>

    Parameters

    a

    1st value of the tuple.

    b

    2nd value of the tuple.

    c

    3rd value of the tuple.

    d

    4th value of the tuple.

    e

    5th value of the tuple.

    g

    6th value of the tuple.

    h

    7th value of the tuple.

    Return Value

    A tuple in the context implementing this instance.

  • zip(_:_:_:_:_:_:_:_:) Extension method

    Creates a tuple out of eight values in the context implementing this instance.

    Declaration

    Swift

    static func zip<A, B, C, D, E, G, H, I>(_ a: Kind<Self, A>,
                                               _ b: Kind<Self, B>,
                                               _ c: Kind<Self, C>,
                                               _ d: Kind<Self, D>,
                                               _ e: Kind<Self, E>,
                                               _ g: Kind<Self, G>,
                                               _ h: Kind<Self, H>,
                                               _ i: Kind<Self, I>) -> Kind<Self, (A, B, C, D, E, G, H, I)>

    Parameters

    a

    1st value of the tuple.

    b

    2nd value of the tuple.

    c

    3rd value of the tuple.

    d

    4th value of the tuple.

    e

    5th value of the tuple.

    g

    6th value of the tuple.

    h

    7th value of the tuple.

    i

    8th value of the tuple.

    Return Value

    A tuple in the context implementing this instance.

  • zip(_:_:_:_:_:_:_:_:_:) Extension method

    Creates a tuple out of nine values in the context implementing this instance.

    Declaration

    Swift

    static func zip<A, B, C, D, E, G, H, I, J>(_ a: Kind<Self, A>,
                                                  _ b: Kind<Self, B>,
                                                  _ c: Kind<Self, C>,
                                                  _ d: Kind<Self, D>,
                                                  _ e: Kind<Self, E>,
                                                  _ g: Kind<Self, G>,
                                                  _ h: Kind<Self, H>,
                                                  _ i: Kind<Self, I>,
                                                  _ j: Kind<Self, J>) -> Kind<Self, (A, B, C, D, E, G, H, I, J)>

    Parameters

    a

    1st value of the tuple.

    b

    2nd value of the tuple.

    c

    3rd value of the tuple.

    d

    4th value of the tuple.

    e

    5th value of the tuple.

    g

    6th value of the tuple.

    h

    7th value of the tuple.

    i

    8th value of the tuple.

    j

    9th value of the tuple.

    Return Value

    A tuple in the context implementing this instance.

  • map(_:_:_:) Extension method

    Combines the result of two computations in the context implementing this instance, using the provided function.

    Declaration

    Swift

    static func map<A, B, Z>(_ a: Kind<Self, A>,
                             _ b: Kind<Self, B>,
                             _ f: @escaping (A, B) -> Z) -> Kind<Self, Z>

    Parameters

    a

    1st computation.

    b

    2nd computation.

    f

    Combination function.

    Return Value

    Result of combining the provided computations, in the context implementing this instance.

  • map(_:_:_:_:) Extension method

    Combines the result of three computations in the context implementing this instance, using the provided function.

    Declaration

    Swift

    static func map<A, B, C, Z>(_ a: Kind<Self, A>,
                                _ b: Kind<Self, B>,
                                _ c: Kind<Self, C>,
                                _ f: @escaping (A, B, C) -> Z) -> Kind<Self, Z>

    Parameters

    a

    1st computation.

    b

    2nd computation.

    c

    3rd computation.

    f

    Combination function.

    Return Value

    Result of combining the provided computations, in the context implementing this instance.

  • map(_:_:_:_:_:) Extension method

    Combines the result of four computations in the context implementing this instance, using the provided function.

    Declaration

    Swift

    static func map<A, B, C, D, Z>(_ a: Kind<Self, A>,
                                   _ b: Kind<Self, B>,
                                   _ c: Kind<Self, C>,
                                   _ d: Kind<Self, D>,
                                   _ f: @escaping (A, B, C, D) -> Z) -> Kind<Self, Z>

    Parameters

    a

    1st computation.

    b

    2nd computation.

    c

    3rd computation.

    d

    4th computation.

    f

    Combination function.

    Return Value

    Result of combining the provided computations, in the context implementing this instance.

  • map(_:_:_:_:_:_:) Extension method

    Combines the result of five computations in the context implementing this instance, using the provided function.

    Declaration

    Swift

    static func map<A, B, C, D, E, Z>(_ a: Kind<Self, A>,
                                      _ b: Kind<Self, B>,
                                      _ c: Kind<Self, C>,
                                      _ d: Kind<Self, D>,
                                      _ e: Kind<Self, E>,
                                      _ f: @escaping (A, B, C, D, E) -> Z) -> Kind<Self, Z>

    Parameters

    a

    1st computation.

    b

    2nd computation.

    c

    3rd computation.

    d

    4th computation.

    e

    5th computation.

    f

    Combination function.

    Return Value

    Result of combining the provided computations, in the context implementing this instance.

  • map(_:_:_:_:_:_:_:) Extension method

    Combines the result of six computations in the context implementing this instance, using the provided function.

    Declaration

    Swift

    static func map<A, B, C, D, E, G, Z>(_ a: Kind<Self, A>,
                                         _ b: Kind<Self, B>,
                                         _ c: Kind<Self, C>,
                                         _ d: Kind<Self, D>,
                                         _ e: Kind<Self, E>,
                                         _ g: Kind<Self, G>,
                                         _ f: @escaping (A, B, C, D, E, G) -> Z) -> Kind<Self, Z>

    Parameters

    a

    1st computation.

    b

    2nd computation.

    c

    3rd computation.

    d

    4th computation.

    e

    5th computation.

    g

    6th computation.

    f

    Combination function.

    Return Value

    Result of combining the provided computations, in the context implementing this instance.

  • map(_:_:_:_:_:_:_:_:) Extension method

    Combines the result of seven computations in the context implementing this instance, using the provided function.

    Declaration

    Swift

    static func map<A, B, C, D, E, G, H, Z>(_ a: Kind<Self, A>,
                                            _ b: Kind<Self, B>,
                                            _ c: Kind<Self, C>,
                                            _ d: Kind<Self, D>,
                                            _ e: Kind<Self, E>,
                                            _ g: Kind<Self, G>,
                                            _ h: Kind<Self, H>,
                                            _ f: @escaping (A, B, C, D, E, G, H) -> Z) -> Kind<Self, Z>

    Parameters

    a

    1st computation.

    b

    2nd computation.

    c

    3rd computation.

    d

    4th computation.

    e

    5th computation.

    g

    6th computation.

    h

    7th computation.

    f

    Combination function.

    Return Value

    Result of combining the provided computations, in the context implementing this instance.

  • map(_:_:_:_:_:_:_:_:_:) Extension method

    Combines the result of eight computations in the context implementing this instance, using the provided function.

    Declaration

    Swift

    static func map<A, B, C, D, E, G, H, I, Z>(_ a: Kind<Self, A>,
                                               _ b: Kind<Self, B>,
                                               _ c: Kind<Self, C>,
                                               _ d: Kind<Self, D>,
                                               _ e: Kind<Self, E>,
                                               _ g: Kind<Self, G>,
                                               _ h: Kind<Self, H>,
                                               _ i: Kind<Self, I>,
                                               _ f: @escaping (A, B, C, D, E, G, H, I) -> Z) -> Kind<Self, Z>

    Parameters

    a

    1st computation.

    b

    2nd computation.

    c

    3rd computation.

    d

    4th computation.

    e

    5th computation.

    g

    6th computation.

    h

    7th computation.

    i

    8th computation.

    f

    Combination function.

    Return Value

    Result of combining the provided computations, in the context implementing this instance.

  • Combines the result of nine computations in the context implementing this instance, using the provided function.

    Declaration

    Swift

    static func map<A, B, C, D, E, G, H, I, J, Z>(_ a: Kind<Self, A>,
                                                  _ b: Kind<Self, B>,
                                                  _ c: Kind<Self, C>,
                                                  _ d: Kind<Self, D>,
                                                  _ e: Kind<Self, E>,
                                                  _ g: Kind<Self, G>,
                                                  _ h: Kind<Self, H>,
                                                  _ i: Kind<Self, I>,
                                                  _ j: Kind<Self, J>,
                                                  _ f: @escaping (A, B, C, D, E, G, H, I, J) -> Z) -> Kind<Self, Z>

    Parameters

    a

    1st computation.

    b

    2nd computation.

    c

    3rd computation.

    d

    4th computation.

    e

    5th computation.

    g

    6th computation.

    h

    7th computation.

    i

    8th computation.

    j

    9th computation.

    f

    Combination function.

    Return Value

    Result of combining the provided computations, in the context implementing this instance.