takeIf method

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

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

Implementation

@pragma('vm:prefer-inline')
@pragma('dart2js:tryInline')
T? takeIf(bool Function(T) predicate) {
  if (predicate(this as T)) return this as T;
  return null;
}