takeIf method

  1. @experimental
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')
@experimental
T? takeIf(bool Function(T) predicate) {
  if (predicate(this as T)) return this as T;
  return null;
}