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.

  • sequence(_:) Extension method

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

    Declaration

    Swift

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

    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

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