Reducible

public protocol Reducible : Foldable

Reducible augments the functions provided by Foldable with reducing functions that do not need an initial value.

  • Eagerly reduces a structure of values from left to right, also performing a transformation of values.

    Declaration

    Swift

    static func reduceLeftTo<A, B>(
        _ fa: Kind<Self, A>,
        _ f: (A) -> B,
        _ g: (B, A) -> B) -> B

    Parameters

    fa

    Structure of values.

    f

    Transforming function.

    g

    Folding function.

    Return Value

    Summary value of this reduction.

  • Lazily reduces a structure of values from right to left, also performing a transformation of values.

    Declaration

    Swift

    static func reduceRightTo<A, B>(
        _ fa: Kind<Self, A>,
        _ f: (A) -> B,
        _ g: (A, Eval<B>) -> Eval<B>) -> Eval<B>

    Parameters

    fa

    Structure of values.

    f

    Transforming function.

    g

    Folding function.

    Return Value

    Potentially lazy summary value of this reduction.

  • reduceLeft(_:_:) Extension method

    Eagerly reduces a structure of values from left to right without transforming them.

    Declaration

    Swift

    static func reduceLeft<A>(
        _ fa: Kind<Self, A>,
        _ f: (A, A) -> A) -> A

    Parameters

    fa

    Structure of values.

    f

    Folding function.

    Return Value

    Summary value of this reduction.

  • reduceRight(_:_:) Extension method

    Lazily reduces a structure of values from right to left without transforming them.

    Declaration

    Swift

    static func reduceRight<A>(
        _ fa: Kind<Self, A>,
        _ f: (A, Eval<A>) -> Eval<A>) -> Eval<A>

    Parameters

    fa

    Structure of values.

    f

    Folding function.

    Return Value

    Potentially lazy summary value of this reduction.

  • Reduces the elements of a structure down to a single value by applying the provided transformation and aggregation funtions in a left-associative manner.

    Declaration

    Swift

    static func reduceLeftToOption<A, B>(
        _ fa: Kind<Self, A>,
        _ f: @escaping (A) -> B,
        _ g: @escaping (B, A) -> B) -> Option<B>

    Parameters

    fa

    Value to be folded.

    f

    Transforming function.

    g

    Folding function.

    Return Value

    Optional summary value resulting from the folding process. It will be an Option.none if the structure is empty, or a value if not.

  • Reduces the elements of a structure down to a single value by applying the provided transformation and aggregation functions in a right-associative manner.

    Declaration

    Swift

    static func reduceRightToOption<A, B>(
        _ fa: Kind<Self, A>,
        _ f: @escaping (A) -> B,
        _ g: @escaping (A, Eval<B>) -> Eval<B>) -> Eval<Option<B>>

    Parameters

    fa

    Value to be folded.

    f

    Transforming function.

    g

    Folding function.

    Return Value

    Optional summary value resulting from the folding process. It will be an Option.none if the structure is empty, or a value if not.

  • isEmpty(_:) Extension method

    Checks if a structure of values is empty.

    An instance of Reducible is never empty.

    Declaration

    Swift

    static func isEmpty<A>(_ fa: Kind<Self, A>) -> Bool

    Parameters

    fa

    Structure of values.

    Return Value

    false if the structure contains any value, true otherwise.

  • nonEmpty(_:) Extension method

    Checks if a structure of values is not empty.

    An instance of Reducible is always non-empty.

    Declaration

    Swift

    static func nonEmpty<A>(_ fa: Kind<Self, A>) -> Bool

    Parameters

    fa

    Structure of values.

    Return Value

    true if the structure contains any value, false otherwise.

  • reduce(_:) Extension method

    Reduces a structure of values to a summary value using the combination capabilities of the Semigroup instance of the underlying type.

    Declaration

    Swift

    static func reduce<A>(_ fa: Kind<Self, A>) -> A where A : Semigroup

    Parameters

    fa

    Structure of values.

    Return Value

    Summary value of this reduction.

  • reduceMap(_:_:) Extension method

    Reduces a structure of values by mapping them to a type with a Semigroup instance, and using its combination capabilities.

    Declaration

    Swift

    static func reduceMap<A, B: Semigroup>(
        _ fa: Kind<Self, A>,
        _ f: (A) -> B) -> B

    Parameters

    fa

    Structure of values.

    f

    Mapping function.

    Return Value

    Summary value of this reduction.