takeIf method

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

Returns value if it satisfies the predicate, otherwise null Usage: number.takeIf((it) => it > 0)

Implementation

T? takeIf(bool Function(T it) predicate) {
  return predicate(this) ? this : null;
}