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

Kotlin's stdlib defines `compose` style behavior with `andThen`-like helpers. Given the standard mathematical `compose` where `(f compose g)(x) == f(g(x))`, what does `pipeline(2)` print?

infix fun <P1, R, R2> ((R) -> R2).compose(f: (P1) -> R): (P1) -> R2 = { p1 -> this(f(p1)) } val square: (Int) -> Int = { it * it } val inc: (Int) -> Int = { it + 1 } val pipeline = inc compose square println(pipeline(2))