Skip to content

Instantly share code, notes, and snippets.

@humanscape-david
Created June 30, 2020 04:25
Show Gist options
  • Select an option

  • Save humanscape-david/6ce357939d77c8d1184eaadf4334e1c4 to your computer and use it in GitHub Desktop.

Select an option

Save humanscape-david/6ce357939d77c8d1184eaadf4334e1c4 to your computer and use it in GitHub Desktop.
코틀린에서 합성함수의 일반화
fun main(args: Array<String>) {
val addThree = { i: Int -> i + 3 }
val twice = { i: Int -> i * 2 }
val composedFunc = addThree compose twice
println(composedFunc(3)) // 9 출력
}
infix fun <F, G, R> ((F) -> R).compose(g: (G) -> F): (G) -> R {
return { gInput: G -> this(g(gInput))}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment