Skip to content

Instantly share code, notes, and snippets.

@humanscape-david
Last active June 30, 2020 05:11
Show Gist options
  • Select an option

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

Select an option

Save humanscape-david/fb392dd76cac16e3bd18e7e91844eb86 to your computer and use it in GitHub Desktop.
매개 변수를 사용한 합성 예
val absolute = { i: List<Int> -> i.map { it -> abs(it) } }
val negative = { i: List<Int> -> i.map { it -> -it } }
val minimun = { i: List<Int> -> i.min() }
// compose를 사용하지 않고 구현
val result1 = minimun(negative(absolute(listOf(3, -1, 5, -2, -4, 8, 14))))
println(result1) // -14 출력
// compose를 사용하여 타입 선언 없이 구현 => 포인트 프리 스타일 프로그래밍
val composed = minimun compose negative compose absolute
val result2 = composed(listOf(3, -1, 5, -2, -4, 8, 14))
println(result2) // -14 출력
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment