boxed
boxed copied to clipboard
Add Option.filter and Result.filter
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.