Using Kotlin takeIf (or takeUnless)
Published in
3 min readNov 28, 2017
In Kotlin’s standard functions, there’s two function i.e. takeIf
and takeUnless
, that at first glance, what’s so special about it? Is it pretty much just if
?
Or one could go the extreme, replace every if
it sees as below (NOT recommended).
// Original Code
if (status) { doThis() }// Modified Code
takeIf { status }?.apply { doThis() }