filter<T> function

Option<T> Function(Option<T> option) filter<T>(
  1. bool predicate(
    1. T value
    )
)

Using the given predicate, conditionally convert the Option to a None.

expect(
  some('hello').chain(filter((s) => s == 'hello')),
  some('hello'),
);
expect(
  some('asdf').chain(filter((s) => s == 'hello')),
  none(),
);

Implementation

Option<T> Function(Option<T> option) filter<T>(
  bool Function(T value) predicate,
) =>
    flatMap(fromPredicateK(predicate));