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

Given these composition helpers, what does `(f andThen g)(2)` and `(f compose g)(2)` evaluate to respectively?

infix fun <A, B, C> ((A) -> B).andThen(g: (B) -> C): (A) -> C = { a -> g(this(a)) } infix fun <A, B, C> ((B) -> C).compose(f: (A) -> B): (A) -> C = { a -> this(f(a)) } val f = { x: Int -> x + 1 } val g = { x: Int -> x * 10 }