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.

  • Folds over the result of this computation by accepting an effect to execute in case of error, and another one in the case of success.

    Declaration

    Swift

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

    Parameters

    f

    Function to run in case of error.

    g

    Function to run in case of success.

    Return Value

    A computation from the result of applying the provided functions to the result of this computation.

  • Retries this computation if it fails based on the provided retrial policy.

    This computation will be at least executed once, and if it fails, it will be retried according to the policy.

    Declaration

    Swift

    func retry<S, O, E>(_ policy: Schedule<D, E, S, O>) -> EnvIO<D, E, A> where F == IOPartial<E>, E : Error

    Parameters

    policy

    Retrial policy.

    Return Value

    A computation that is retried based on the provided policy when it fails.

  • Retries this computation if it fails based on the provided retrial policy, providing a default computation to handle failures after retrial.

    This computation will be at least executed once, and if it fails, it will be retried according to the policy.

    Declaration

    Swift

    func retry<S, O, B, E: Error>(_ policy: Schedule<D, E, S, O>, orElse: @escaping (E, O) -> EnvIO<D, E, B>) -> EnvIO<D, E, Either<B, A>> where F == IOPartial<E>

    Parameters

    policy

    Retrial policy.

    orElse

    Function to handle errors after retrying.

    Return Value

    A computation that is retried based on the provided policy when it fails.

  • Repeats this computation until the provided repeating policy completes, or until it fails.

    This computation will be at least executed once, and if it succeeds, it will be repeated additional times according to the policy.

    Declaration

    Swift

    func `repeat`<S, O, E: Error>(_ policy: Schedule<D, A, S, O>, onUpdateError: @escaping () -> E) -> EnvIO<D, E, O> where F == IOPartial<E>

    Parameters

    policy

    Repeating policy.

    onUpdateError

    A function providing an error in case the policy fails to update properly.

    Return Value

    A computation that is repeated based on the provided policy when it succeeds.

  • Repeats this computation until the provided repeating policy completes, or until it fails, with a function to handle potential failures.

    Declaration

    Swift

    func `repeat`<S, O, B, E: Error>(_ policy: Schedule<D, A, S, O>, onUpdateError: @escaping () -> E, orElse: @escaping (E, O?) -> EnvIO<D, E, B>) -> EnvIO<D, E, Either<B, O>> where F == IOPartial<E>

    Parameters

    policy

    Repeating policy.

    onUpdateError

    A function providing an error in case the policy fails to update properly.

    orElse

    A function to return a computation in case of error.

    Return Value

    A computation that is repeated based on the provided policy when it succeeds.

  • Transforms the type arguments of this EnvIO.

    Declaration

    Swift

    func bimap<E: Error, EE: Error, B>(_ fe: @escaping (E) -> EE, _ fa: @escaping (A) -> B) -> EnvIO<D, EE, B> where F == IOPartial<E>

    Parameters

    fe

    Function to transform the error type argument.

    fa

    Function to transform the output type argument.

    Return Value

    An EnvIO with both type arguments transformed.

  • 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>, 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>, 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 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.

  • Sleep for the specified amount of time.

    Declaration

    Swift

    static func sleep<E>(_ interval: DispatchTimeInterval) -> EnvIO<D, E, Void> where F == IOPartial<E>, E : Error

    Parameters

    interval

    Time to sleep.

    Return Value

    A computation that sleeps for the specified amount of time.

  • Sleep for the specified amount of time.

    Declaration

    Swift

    static func sleep<E>(_ interval: TimeInterval) -> EnvIO<D, E, Void> where F == IOPartial<E>, E : Error

    Parameters

    interval

    Time to sleep.

    Return Value

    A computation that sleeps for the specified amount of time.

  • 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.