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

    Example

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

    Typeparam

    TSource The type of source elements.

    Returns

    A sequence with source elements in their original order.

    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.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns IEnumerable<TSource>

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

    Example

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

    Typeparam

    TSource The type of source elements.

    Returns

    A sequence with source elements in their original order.

    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.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    • message: string

      The message to use for thrown errors.

    Returns IEnumerable<TSource>

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

    Example

    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'

    Typeparam

    TSource The type of source elements.

    Typeparam

    TError The type of error to be thrown.

    Returns

    A sequence with source elements in their original order.

    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.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

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

      Type of error to throw.

        • new (message?: string): TError
        • Parameters

          • Optional message: string

          Returns TError

    Returns IEnumerable<TSource>

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

    Example

    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'

    Typeparam

    TSource The type of source elements.

    Typeparam

    TError The type of error to be thrown.

    Returns

    A sequence with source elements in their original order.

    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.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    • message: string

      The message to use for thrown errors.

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

      Type of error to throw.

        • new (message?: string): TError
        • Parameters

          • Optional message: string

          Returns TError

    Returns IEnumerable<TSource>

Generated using TypeDoc