Skip to content

filterMap

filterMap<A, B>(f): (data) => readonly B[]

Defined in: Data/Arr.ts:178

Maps each element to a Maybe and collects only the Some values. Combines map and filter in a single pass.

A

B

(a) => Maybe<B>

(data) => readonly B[]

const parseNum = (s: string): Maybe<number> => {
  const n = Number(s);
  return isNaN(n) ? Maybe.none() : Maybe.some(n);
};

pipe(["1", "abc", "3"], Arr.filterMap(parseNum)); // [1, 3]