• Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Type Parameters

    • TSource

    Parameters

    • src: Iterable<TSource>

      The source iterable.

    • predicate: (item: TSource, index: number) => boolean

      A function to test each element for a condition. If false, an error will be thrown.

    Returns IEnumerable<TSource>

    A sequence with source elements in their original order.

    const items = [1, 2, '3'];
    const sum = from(items).assert(x => typeof x === 'number').sum(); // throws due to '3'

    TSource The type of source elements.

  • Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Type Parameters

    • TSource

    Parameters

    • src: Iterable<TSource>

      The source iterable.

    • predicate: (item: TSource, index: number) => boolean

      A function to test each element for a condition. If false, an error will be thrown.

    • message: string

      The message to use for thrown errors.

    Returns IEnumerable<TSource>

    A sequence with source elements in their original order.

    const items = [1, 2, '3'];
    const sum = from(items).assert(x => typeof x === 'number', 'Should be number').sum(); // throws due to '3'

    TSource The type of source elements.

  • Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Type Parameters

    • TSource
    • TError extends Error

    Parameters

    • src: Iterable<TSource>

      The source iterable.

    • predicate: (item: TSource, index: number) => boolean

      A function to test each element for a condition. If false, an error will be thrown.

    • errorType: new (message?: string) => TError

      Type of error to throw.

    Returns IEnumerable<TSource>

    A sequence with source elements in their original order.

    class MyError extends Error {}
    const items = [1, 2, '3'];
    const sum = from(items).assert(x => typeof x === 'number', MyError).sum(); // throws instance of MyError due to '3'

    TSource The type of source elements.

    TError The type of error to be thrown.

  • Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Type Parameters

    • TSource
    • TError extends Error

    Parameters

    • src: Iterable<TSource>

      The source iterable.

    • predicate: (item: TSource, index: number) => boolean

      A function to test each element for a condition. If false, an error will be thrown.

    • message: string

      The message to use for thrown errors.

    • errorType: new (message?: string) => TError

      Type of error to throw.

    Returns IEnumerable<TSource>

    A sequence with source elements in their original order.

    class MyError extends Error {}
    const items = [1, 2, '3'];
    const sum = from(items).assert(x => typeof x === 'number', 'Must be number', MyError).sum(); // throws instance of MyError with message due to '3'

    TSource The type of source elements.

    TError The type of error to be thrown.