NonEmptyReducible

public protocol NonEmptyReducible : Reducible

NonEmptyReducible defines a Reducible in terms of another type that has an instance of Foldable and a method that is able to split a structure of values in a first value and the rest of the values in the structure.

  • Undocumented

    Declaration

    Swift

    associatedtype G : Foldable
  • Divides a structure of values into a tuple that represents the first value of the structure (first component of the tuple) and the rest of values of the structure (second component of the tuple)

    Declaration

    Swift

    static func split<A>(_ fa: Kind<Self, A>) -> (A, Kind<G, A>)

    Parameters

    fa

    Structure of values.

    Return Value

    Tuple containing the first and rest of values in the structure.

  • foldLeft(_:_:_:) Extension method

    Declaration

    Swift

    static func foldLeft<A, B>(
        _ fa: Kind<Self, A>,
        _ b: B,
        _ f: @escaping (B, A) -> B) -> B
  • foldRight(_:_:_:) Extension method

    Declaration

    Swift

    static func foldRight<A, B>(
        _ fa: Kind<Self, A>,
        _ b: Eval<B>,
        _ f: @escaping (A, Eval<B>) -> Eval<B>) -> Eval<B>
  • reduceLeftTo(_:_:_:) Extension method

    Declaration

    Swift

    static func reduceLeftTo<A, B>(
        _ fa: Kind<Self, A>,
        _ f: (A) -> B,
        _ g: @escaping (B, A) -> B) -> B
  • reduceRightTo(_:_:_:) Extension method

    Declaration

    Swift

    static func reduceRightTo<A, B>(
        _ fa: Kind<Self, A>,
        _ f: @escaping (A) -> B,
        _ g: @escaping (A, Eval<B>) -> Eval<B>) -> Eval<B>
  • fold(_:) Extension method

    Folds a structure of values provided that its type has an instance of Monoid.

    It uses the monoid empty value as initial value and the combination method for the fold.

    Declaration

    Swift

    static func fold<A>(_ fa: Kind<Self, A>) -> A where A : Monoid

    Parameters

    fa

    Value to be folded.

    Return Value

    Summary value resulting from the folding process.

  • find(_:_:) Extension method

    Looks for an element that matches a given predicate.

    Declaration

    Swift

    static func find<A>(
        _ fa: Kind<Self, A>,
        _ f: @escaping (A) -> Bool) -> Option<A>

    Parameters

    fa

    Structure of values where the element matching the predicate needs to be found.

    f

    Predicate.

    Return Value

    A value if there is any that matches the predicate, or Option.none.

  • exists(_:_:) Extension method

    Checks if any element in a structure matches a given predicate.

    Declaration

    Swift

    static func exists<A>(
        _ fa: Kind<Self, A>,
        _ predicate: @escaping (A) -> Bool) -> Bool

    Parameters

    fa

    Structure of values where the element matching the predicate needs to be found.

    predicate

    Predicate.

    Return Value

    A boolean value indicating if any elements in the structure match the predicate.

  • forall(_:_:) Extension method

    Checks if all elements in a structure match a given predicate.

    Declaration

    Swift

    static func forall<A>(
        _ fa: Kind<Self, A>,
        _ predicate: @escaping (A) -> Bool) -> Bool

    Parameters

    fa

    Structure of values where all elements should match the predicate.

    predicate

    Predicate.

    Return Value

    A boolean value indicating if all elements in the structure match the predicate.

  • count(_:) Extension method

    Counts how many elements a structure contains.

    Declaration

    Swift

    static func count<A>(_ fa: Kind<Self, A>) -> Int64

    Parameters

    fa

    Structure of values.

    Return Value

    An integer value with the count of how many elements are contained in the structure.

  • get(_:_:) Extension method

    Obtains a specific element of a structure of elements given its indexed position.

    Declaration

    Swift

    static func get<A>(
        _ fa: Kind<Self, A>,
        _ index: Int64) -> Option<A>

    Parameters

    fa

    Structure of values.

    index

    Indexed position of the element to retrieve.

    Return Value

    A value if there is any at the given position, or Option.none otherwise.

  • foldM(_:_:_:) Extension method

    Performs a monadic left fold from the source context to the target monad.

    Declaration

    Swift

    static func foldM<H: Monad, A, B>(
        _ fa: Kind<Self, A>,
        _ b: B,
        _ f: @escaping (B, A) -> Kind<H, B>) -> Kind<H, B>

    Parameters

    fa

    Structure of values.

    b

    Initial value for the fold.

    f

    Folding function.

    Return Value

    Summary value resulting from the folding process in the context of the target monad.