Function find

  • Returns the first matching value. If the value is not found return def, and if def is not defined throw NotFound.

    Type Parameters

    • Iter extends AnyIt<unknown>
    • V extends unknown
    • D = V

    Parameters

    • iter: Iter

      The iterable to find against.

    • condition: V | Matcher<V>

      A value or a matcher function.

    • Optional def: typeof notDefined | D

      The default value to return if no value has been found.

    Returns AnyItResult<Iter, D | V>

    Example

    // Returns 2
    it.filter([1, 2, 3], x => x == 2)

    Example

    // Returns 2
    it.filter([1, 2, 3], 2)

    Example

    // Returns 10
    it.filter([1, 2, 3], -1, 10)

    Example

    // Throws NotFound
    it.filter([1, 2, 3], -1)

    Throws

    NotFound - No value has been found and def is not defined.