@mikuroxina/mini-fn
    Preparing search index...

    Function span

    • Splits the list into a tuple of the longest prefix satisfies pred and the rest. It is equivalent to [takeWhile(pred)(list), dropWhile(pred)(list)].

      Type Parameters

      • T

      Parameters

      • pred: (t: T) => boolean

        The condition to split.

      Returns (list: List.List<T>) => [List.List<T>, List.List<T>]

      The tuple of split of the list.

      Examples

      {
      const [left, right] = span((x: number) => x < 3)(
      fromArray([1, 2, 3, 4, 1, 2, 3, 4]),
      );
      expect(toArray(left)).toStrictEqual([1, 2]);
      expect(toArray(right)).toStrictEqual([3, 4, 1, 2, 3, 4]);
      }
      {
      const [left, right] = span((x: number) => x < 9)(fromArray([1, 2, 3]));
      expect(toArray(left)).toStrictEqual([1, 2, 3]);
      expect(toArray(right)).toStrictEqual([]);
      }
      {
      const [left, right] = span((x: number) => x < 0)(fromArray([1, 2, 3]));
      expect(toArray(left)).toStrictEqual([]);
      expect(toArray(right)).toStrictEqual([1, 2, 3]);
      }