Skip to main content

findLast

Callable


  • Find the last element in a Traversable by a given predicate.

    Example

    findLast(take(counter(), 123), (i) => i > 10)
    // => 122

    function* foobar() {
    yield 'foo'
    yield 'bar'
    }
    findLast(foobar(), (str) => str.startsWith('bar'))
    // => "bar"

    findLast(take(counter(100), 100), (i) => i < 10)
    // => Nothing

    Alternatives


    Type parameters

    • T

      The element type.

    Parameters

    • xs: Traversable<T, unknown>

      The Mappable search in.

    • by: (item: T) => boolean

      The predicate to search with.

    Returns Maybe<T>

    The last element that satisfies the given predicate, Nothing otherwise.