takeIf method

T? takeIf(
  1. bool predicate(
    1. T obj
    )
)

Returns this if it satisfies the given predicate or null, if it doesn't.

Implementation

T? takeIf(bool Function(T obj) predicate) {
  if (predicate(this)) {
    return this;
  }
  return null;
}