takeUnlessLazy method

T? takeUnlessLazy(
  1. bool predicate(
    1. T value
    )
)

Returns this value if predicate returns false for it, otherwise null.

The opposite of takeIfLazy. Useful for negated predicate conditions.

Example:

final validNumber = input.takeUnlessLazy((n) => n < 0);
// Returns input if it's not negative, null if negative

Implementation

T? takeUnlessLazy(bool Function(T value) predicate) {
  if (!predicate(this)) return this;

  return null;
}