Traverse

public protocol Traverse : Foldable, Functor

Traverse provides a type with the ability to traverse a structure with an effect.

  • Maps each element of a structure to an effect, evaluates them from left to right and collects the results.

    Declaration

    Swift

    static func traverse<G: Applicative, A, B>(
        _ fa: Kind<Self, A>,
        _ f: @escaping (A) -> Kind<G, B>) -> Kind<G, Kind<Self, B>>

    Parameters

    fa

    A structure of values.

    f

    A function producing an effect.

    Return Value

    Results collected under the context of the effect provided by the function.

  • parTraverse(_:_:) Extension method

    Maps each element of a structure to an effect, evaluates in parallel and collects the results.

    Declaration

    Swift

    static func parTraverse<G: Concurrent, A, B>(
        _ fa: Kind<Self, A>,
        _ f: @escaping (A) -> Kind<G, B>) -> Kind<G, Kind<Self, B>>

    Parameters

    fa

    A structure of values.

    f

    A function producing an effect.

    Return Value

    Results collected under the context of the effect provided by the function.

  • parSequence(_:) Extension method

    Evaluate each effect in a structure of values in parallel and collects the results.

    Declaration

    Swift

    static func parSequence<G, A>(_ fa: Kind<Self, Kind<G, A>>) -> Kind<G, Kind<Self, A>> where G : Concurrent

    Parameters

    fga

    A structure of values.

    Return Value

    Results collected under the context of the effects.

  • parFlatTraverse(_:_:) Extension method

    A parallel traverse followed by flattening the inner result.

    Declaration

    Swift

    static func parFlatTraverse<G: Concurrent, A, B>(
        _ fa: Kind<Self, A>,
        _ f: @escaping (A) -> Kind<G, Kind<Self, B>>) -> Kind<G, Kind<Self, B>>

    Parameters

    fa

    A structure of values.

    f

    A transforming function yielding nested effects.

    Return Value

    Results collected and flattened under the context of the effects.

  • sequence(_:) Extension method

    Evaluate each effect in a structure of values and collects the results.

    Declaration

    Swift

    static func sequence<G: Applicative, A, B>(_ fga: Kind<Self, B>) -> Kind<G, Kind<Self, A>>
        where B: Kind<G, A>

    Parameters

    fga

    A structure of values.

    Return Value

    Results collected under the context of the effects.

  • flatTraverse(_:_:) Extension method

    A traverse followed by flattening the inner result.

    Declaration

    Swift

    static func flatTraverse<G: Applicative, A, B>(
        _ fa: Kind<Self, A>,
        _ f: @escaping (A) -> Kind<G, Kind<Self, B>>) -> Kind<G, Kind<Self, B>>

    Parameters

    fa

    A structure of values.

    f

    A transforming function yielding nested effects.

    Return Value

    Results collected and flattened under the context of the effects.

  • scanLeft(_:_:_:) Extension method

    Maps each element of a structure using a stateful function.

    Declaration

    Swift

    static func scanLeft<A, B, S>(
        _ fa: Kind<Self, A>,
        _ initialState: S,
        _ f: @escaping (A) -> State<S, B>) -> Kind<Self, B>

    Parameters

    fa

    A structure of values.

    initialState

    The state that will be passed to f initially.

    f

    A stateful function.

    Return Value

    A new structure with the results of the function.

  • scanLeft(_:_:_:) Extension method

    Maps each element of a structure using a stateful function.

    Declaration

    Swift

    static func scanLeft<A, B>(
        _ fa: Kind<Self, A>,
        _ initialState: B,
        _ f: @escaping (B, A) -> B) -> Kind<Self, B>

    Parameters

    fa

    A structure of values.

    initialState

    The state that will be passed to f initially.

    f

    A stateful function that returns the new state, which will be included in the returned structure.

    Return Value

    A new structure with the results of the function.

  • scanLeftM(_:_:_:) Extension method

    Maps each element of a structure to an effect using a stateful function.

    Declaration

    Swift

    static func scanLeftM<M: Monad, A, B, S>(
        _ fa: Kind<Self, A>,
        _ initialState: Kind<M, S>,
        _ f: @escaping (A) -> StateT<M, S, B>) -> Kind<M, Kind<Self, B>>

    Parameters

    fa

    A structure of values.

    initialState

    The state that will be passed to f initially.

    f

    A stateful function producing an effect.

    Return Value

    Results collected under the context of the effect provided by the function.

  • scanLeftM(_:_:_:) Extension method

    Maps each element of a structure to an effect using a stateful function.

    Declaration

    Swift

    static func scanLeftM<M: Monad, A, B>(
        _ fa: Kind<Self, A>,
        _ initialState: Kind<M, B>,
        _ f: @escaping (B, A) -> Kind<M, B>) -> Kind<M, Kind<Self, B>>

    Parameters

    fa

    A structure of values.

    initialState

    The state that will be passed to f initially.

    f

    A stateful function producing an effect, which will be included in the returned structure.

    Return Value

    Results collected under the context of the effect provided by the function.