boxed icon indicating copy to clipboard operation
boxed copied to clipboard

Add Option.filter and Result.filter

Open AlexSchwabauer opened this issue 1 year ago • 0 comments

Hey, thanks for the nice streamlined library! What I am missing from the API that exists in fp-ts is a filter function for Option and Result.

Here is the reference in fp-ts.

I implemented it in user-land like this for now:

export function OptionFilter<T>(
  option: Option<T>,
  filterFn: (param: T) => boolean
): Option<T> {
  return option.flatMap((value) =>
    filterFn(value) ? Option.Some(value) : Option.None()
  );
}

It would be nice to have this integrated in the library so we can use chaining.

AlexSchwabauer avatar Aug 01 '22 08:08 AlexSchwabauer