takeIf

inline fun <T> T.takeIf(predicate: (T) -> Boolean): T?(source)

Returns this value when predicate is true, or null otherwise.