# Why does takeIf allow nullable receivers in its predicate?

**URL:** <https://discuss.kotlinlang.org/t/why-does-takeif-allow-nullable-receivers-in-its-predicate/30863>\
**Category:** Libraries\
**Created:** [November 25, 2025, 1:25pm UTC](https://discuss.kotlinlang.org/t/why-does-takeif-allow-nullable-receivers-in-its-predicate/30863 "2025-11-25T13:25:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)\
**Post date:** [November 25, 2025, 1:25pm UTC](https://discuss.kotlinlang.org/t/why-does-takeif-allow-nullable-receivers-in-its-predicate/30863/1 "2025-11-25T13:25:45Z")

</div>

The signature of `takeIf` (and `takeUnless`) is:

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

instead of:

`public inline fun <T : Any> T?.takeIf(predicate: (T) -> Boolean): T?`

Why does Kotlin allow `null` as a possible value passed to the predicate? What is the rationale for not restricting `T` to non-null types?
