Skip to main content

type partition

Returns an AsyncReducer that splits the incoming values into two separate outputs based on the given pred predicate. Values for which the predicate is true are fed into the collectorTrue reducer, and other values are fed into the collectorFalse instance. If no collectors are provided the values are collected into arrays.

note

if the predicate is a type guard, the return type is automatically inferred ```

Definition

partition: {
    <T, T2 extends T, RT, RF = RT>(pred: (value: T, index: number) => value is T2, options: {
      collectorTrue: AsyncReducer.Accept<T2, RT>;
      collectorFalse: AsyncReducer.Accept<Exclude<T, T2>, RF>;
    }): AsyncReducer<T, [true: RT, false: RF]>;
    <T, T2 extends T>(pred: (value: T, index: number) => value is T2, options?: {
      collectorTrue?: undefined;
      collectorFalse?: undefined;
    }): AsyncReducer<T, [true: T2[], false: Exclude<T, T2>[]]>;
    <T, RT, RF = RT>(pred: (value: T, index: number) => MaybePromise<boolean>, options: {
      collectorTrue: AsyncReducer.Accept<T, RT>;
      collectorFalse: AsyncReducer.Accept<T, RF>;
    }): AsyncReducer<T, [true: RT, false: RF]>;
    <T>(pred: (value: T, index: number) => MaybePromise<boolean>, options?: {
      collectorTrue?: undefined;
      collectorFalse?: undefined;
    }): AsyncReducer<T, [true: T[], false: T[]]>;
  }