Kleisli

public final class Kleisli<F, D, A> : KleisliOf<F, D, A>

Kleisli represents a function with the signature (D) -> Kind<F, A>.

  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ fa: KleisliOf<F, D, A>) -> Kleisli<F, D, A>

    Parameters

    fa

    Value in the higher-kind form.

    Return Value

    Value cast to Kleisli.

  • Creates a constant Kleisli function.

    Declaration

    Swift

    public static func liftF(_ fa: Kind<F, A>) -> Kleisli<F, D, A>

    Parameters

    fa

    Constant value to return.

    Return Value

    A constant Kleisli function.

  • Initializes a Kleisli value.

    Declaration

    Swift

    public init(_ run: @escaping (D) -> Kind<F, A>)

    Parameters

    run

    Closure to be wrapped in this Kleisli.

  • Inkoves this Kleisli function with an input value.

    Declaration

    Swift

    public func invoke(_ value: D) -> Kind<F, A>

    Parameters

    value

    Input to the function.

    Return Value

    Output of the Kleisli.

  • Pre-composes this Kleisli function with a function transforming the input type.

    Declaration

    Swift

    public func contramap<DD>(_ f: @escaping (DD) -> D) -> Kleisli<F, DD, A>

    Parameters

    f

    Transforming function.

    Return Value

    Composition of the two functions.

  • Pre-composes this Kleisli function with a function transforming the input type obtained from a key path.

    Declaration

    Swift

    public func contramap<DD>(_ keyPath: KeyPath<DD, D>) -> Kleisli<F, DD, A>

    Parameters

    f

    Transforming function.

    Return Value

    Composition of the two functions.

  • Transforms the error type of this EnvIO

    Declaration

    Swift

    func mapError<E: Error, EE: Error>(_ f: @escaping (E) -> EE) -> EnvIO<D, EE, A> where F == IOPartial<E>

    Parameters

    f

    Function transforming the error.

    Return Value

    An EnvIO value with the new error type.

  • Provides the required environment.

    Declaration

    Swift

    func provide<E>(_ d: D) -> IO<E, A> where F == IOPartial<E>, E : Error

    Parameters

    d

    Environment.

    Return Value

    An IO resulting from running this computation with the provided environment.

  • Performs the side effects that are suspended in this IO in a synchronous manner.

    Throws

    Error of type E that may happen during the evaluation of the side-effects. Errors of other types thrown from the evaluation of this IO will cause a fatal error.

    Declaration

    Swift

    func unsafeRunSync<E>(on queue: DispatchQueue = .main) throws -> A where F == IOPartial<E>, D == Any, E : Error

    Parameters

    queue

    Dispatch queue used to execute the side effects. Defaults to the main queue.

    Return Value

    Value produced after running the suspended side effects.

  • Performs the side effects that are suspended in this EnvIO in a synchronous manner.

    Declaration

    Swift

    func unsafeRunSyncEither<E>(on queue: DispatchQueue = .main) -> Either<E, A> where F == IOPartial<E>, D == Any, E : Error

    Parameters

    queue

    Dispatch queue used to execute the side effects. Defaults to the main queue.

    Return Value

    An Either wrapping errors in the left side and values on the right side. Errors of other types thrown from the evaluation of this IO will cause a fatal error.

  • Performs the side effects that are suspended in this EnvIO in an asynchronous manner.

    Declaration

    Swift

    func unsafeRunAsync<E: Error>(on queue: DispatchQueue = .main, _ callback: @escaping Callback<E, A>) where D == Any, F == IOPartial<E>

    Parameters

    queue

    Dispatch queue used to execute the side effects. Defaults to the main queue.

    callback

    A callback function to receive the results of the evaluation. Errors of other types thrown from the evaluation of this IO will cause a fatal error.

  • Zips this Kleisli function with another one with the same input type.

    Declaration

    Swift

    public func zip<B>(_ o: Kleisli<F, D, B>) -> Kleisli<F, D, (A, B)>

    Parameters

    o

    Kleisli function to be zipped with this one.

    Return Value

    A Kleisli function that pairs the output of the two Kleisli functions zipped in this operation.

  • Composes this Kleisli with another one.

    Declaration

    Swift

    public func andThen<C>(_ f: Kleisli<F, A, C>) -> Kleisli<F, D, C>

    Parameters

    f

    Kleisli function to be composed after the this one.

    Return Value

    A Kleisli function that is equivalent to running this Kleisli and then the received one.

  • Composes this Kleisli with a function in Kleisli form.

    Declaration

    Swift

    public func andThen<B>(_ f: @escaping (A) -> Kind<F, B>) -> Kleisli<F, D, B>

    Parameters

    f

    A function to be composed after this Kleisli.

    Return Value

    A Kleisli function that is equivalent to running this Kleisli and then the received one.

  • Composes this Kleisli with a constant value.

    Declaration

    Swift

    public func andThen<B>(_ a: Kind<F, B>) -> Kleisli<F, D, B>

    Parameters

    a

    Constant value.

    Return Value

    A Kleisli function that is equivalent to running this Kleisli and ommitting its result, returning the constant value produced.