FunctionK

open class FunctionK<F, G>

A transformation between two kinds.

As Function1<A, B> represents a transformation from A to B, FunctionK<F, G> represents a transformation from Kind<F, A> to Kind<G, A>. Subclasses of FunctionK need to implement invoke.

  • Initializer

    Declaration

    Swift

    public init()
  • Invokes this transformation.

    Declaration

    Swift

    open func invoke<A>(_ fa: Kind<F, A>) -> Kind<G, A>

    Parameters

    fa

    Input to this function

    Return Value

    Transformed input.

  • Invokes this transformation.

    Declaration

    Swift

    public func callAsFunction<A>(_ fa: Kind<F, A>) -> Kind<G, A>

    Parameters

    fa

    Input to this function

    Return Value

    Transformed input.

  • Composes this function with another one.

    Declaration

    Swift

    public func andThen<H>(_ g: FunctionK<G, H>) -> FunctionK<F, H>

    Parameters

    g

    Function to compose with this one.

    Return Value

    A function that transform the input with this function and the received one afterwards.

  • Composes this function with another one.

    Declaration

    Swift

    public func compose<H>(_ g: FunctionK<H, F>) -> FunctionK<H, G>

    Parameters

    g

    Function to compose with this one.

    Return Value

    A function that transform the input with the received function and this one afterwards.

  • Obtains a natural transformation for the Free Monads of the Functors from this natural transformation.

    Declaration

    Swift

    func free() -> FunctionK<FreePartial<F>, FreePartial<G>>

    Return Value

    A natural transformation for the Free Monads.

  • Obtains a natural transformation from a Free Monad to the underlying Monad.

    Declaration

    Swift

    static func monad() -> FunctionK<FreePartial<G>, G>

    Return Value

    A natural transformation from a Free Monad to its underlying Monad.

  • Obtains an interpreter for Free Monads from this Natural Transformation.

    Declaration

    Swift

    func interpreter() -> FunctionK<FreePartial<F>, G>

    Return Value

    A Natural Transformation to interpret the Free Monad given by the Functor F, into the Monad G.

  • Obtains a natural transformation from a Free Monad to another one that sums two Functors, placing the underlying functor on the left-hand side of the sum.

    Declaration

    Swift

    static func left<FF, GG>() -> FunctionK<F, G>
    where F == FreePartial<FF>, G == FreePartial<EitherKPartial<FF, GG>>

    Return Value

    A natural transformation.

  • Obtains a natural transformation from a Free Monad to another one that sums two Functors, placing the underlying functor on the right-hand side of the sum.

    Declaration

    Swift

    static func right<FF, GG>() -> FunctionK<F, G>
    where F == FreePartial<GG>, G == FreePartial<EitherKPartial<FF, GG>>

    Return Value

    A natural transformation.

  • Obtains a natural transformation that reduces a coyoneda value of a type constructor F even if F is not a functor, provided that you have a way to transform F into a functor G.

    The natural transformation from Coyoneda<F> to a functor G works by transforming Coyoneda<F> to Coyoneda<G> and then reducing the new coyoneda value.

    Declaration

    Swift

    public var transformAndReduce: FunctionK<CoyonedaPartial<F>, G> { get }
  • Combines this natural transformation with another one targetting the same Functor.

    Declaration

    Swift

    func sum<H>(_ h: FunctionK<H, G>) -> FunctionK<EitherKPartial<F, H>, G> where H : Functor

    Parameters

    h

    Natural transformation to be combined.

    Return Value

    A natural transformation that goes from the sum of both Functors into the same target Functor.

  • Identity FunctionK.

    It returns the input unmodified.

    Declaration

    Swift

    static var id: FunctionK<F, F> { get }