MonadReader

public protocol MonadReader : Monad

A MonadReader is a Monad with capabilities to read values from a shared environment.

  • Type of the shared environment

    Declaration

    Swift

    associatedtype D
  • Retrieves the shared environment.

    Declaration

    Swift

    static func ask() -> Kind<Self, D>

    Return Value

    Shared environment.

  • Executes a computation in a modified environment.

    Declaration

    Swift

    static func local<A>(
        _ fa: Kind<Self, A>,
        _ f: @escaping (D) -> D) -> Kind<Self, A>

    Parameters

    fa

    Computation to execute.

    f

    Funtion to modify the environment.

    Return Value

    Computation in the modified environment.

  • reader(_:) Extension method

    Retrieves a function of the current environment.

    Declaration

    Swift

    static func reader<A>(_ f: @escaping (D) -> A) -> Kind<Self, A>

    Parameters

    f

    Selector function to apply to the environment.

    Return Value

    A value extracted from the environment, in the context implementing this instance.