Pairing

public class Pairing<F, G> : PairingOf<F, G> where F : Functor, G : Functor

The Pairing type represents a relationship between Functors F and G, where the sums in one can annihilate the products in the other.

The internals of this type embed a function of the following shape: forall a b c. f a -> g b -> (a -> b -> c) -> c Or equivalently: forall a b. f (a -> b) -> g a -> b

Swift lacks universal quantifiers, so these types are replaced by Any.

  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ value: PairingOf<F, G>) -> Pairing<F, G>

    Parameters

    value

    Value in the higher-kind form.

    Return Value

    Value cast to Pairing.

  • Initializes a Pairing.

    Declaration

    Swift

    public init(_ zap: @escaping (Kind<F, (/*A*/Any) -> /*B*/Any>, Kind<G, /*A*/Any>) -> /*B*/Any)

    Parameters

    zap

    Relationship between the Functors, captured as a function of the form: forall a b. f (a -> b) -> g a -> b

  • Initializes a Pairing.

    Declaration

    Swift

    public init(_ pairing: @escaping (Kind<F, /*A*/Any>, Kind<G, /*B*/Any>, @escaping (/*A*/Any, /*B*/Any) -> /*C*/Any) -> /*C*/Any)

    Parameters

    pairing

    Relationship between the Functors, captured as a function of the form: forall a b c. f a -> g b -> (a -> b -> c) -> c

  • Annihilate the F and G effects by calling the wrapped function in F with the wrapped value

    Declaration

    Swift

    public func zap<A, B>(_ fab: Kind<F, (A) -> B>, _ ga: Kind<G, A>) -> B

    Parameters

    fab

    An F-effectful A -> B

    ga

    A G-effectful A

    Return Value

    A pure B

  • Annilate the F and G effects by extracting the values in their contexts and using the combination function.

    Declaration

    Swift

    public func pair<A, B, C>(_ fa: Kind<F, A>, _ gb: Kind<G, B>, _ f: @escaping (A, B) -> C) -> C

    Parameters

    fa

    An F-effectful value.

    gb

    A G-effectful value.

    f

    A function to combine the values in both contexts.

    Return Value

    Result of annihilating both effectful values and combining them with the provided function.

  • Explores the space given by one Functor, using the other as an explorer.

    Declaration

    Swift

    public func select<A, B>(_ fa: Kind<F, A>, _ ggb: Kind<G, Kind<G, B>>) -> Kind<G, B>

    Parameters

    fa

    Explorer Functorial value.

    ggb

    Spact Functorial value.

    Return Value

    Result of the exploration.

  • Annihilates the F and G effectful values with arguments flipped.

    Declaration

    Swift

    public func pairFlipped<A, B, C>(_ ga: Kind<G, A>, _ fb: Kind<F, B>, _ f: @escaping (A, B) -> C) -> C

    Parameters

    ga

    A G-effectful value.

    fb

    An F-effectful value.

    f

    Combination function.

    Return Value

    Result of annihilating both effectful values and combining them with the provided function.

  • Lifts this Pairing to use it for a StateT-StoreT pairing.

    Declaration

    Swift

    public func pairStateTStoreT<S>() -> Pairing<StateTPartial<F, S>, StoreTPartial<S, G>>

    Return Value

    A pairing for StateT-StoreT where their base Monad and Comonad are paired with this pairing.

  • Lifts this Pairing to use it for a WriterT-TracedT pairing.

    Declaration

    Swift

    public func pairWriterTTracedT<W>() -> Pairing<WriterTPartial<F, W>, TracedTPartial<W, G>>

    Return Value

    A pairing for WriterT-TracedT where their base Monad and Comonad are paired with this pairing.

  • Lifts this Pairing to use it for a ReaderT-EnvT pairing.

    Declaration

    Swift

    public func pairReaderTEnvT<R>() -> Pairing<ReaderTPartial<F, R>, EnvTPartial<R, G>>

    Return Value

    A pairing for ReaderT-EnvT where their base Monad and Comonad are paired with this pairing.

  • Provides a Pairing for Id-Id.

    Declaration

    Swift

    static func pairId() -> Pairing<ForId, ForId>

    Return Value

    A Pairing for Id-Id.