Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumKotlinhigher-order function compositionSingle-choice MCQ

When composing functions with nullable intermediate results, what does this chain return for input `4` and for input `-4`?

fun <A, B, C> ((A) -> B?).andThenNullable(g: (B) -> C?): (A) -> C? = { a -> this(a)?.let(g) } val sqrtIfPos = { x: Int -> if (x >= 0) x else null } val describe = { x: Int -> if (x > 2) "big" else null } val pipe = sqrtIfPos.andThenNullable(describe)