Last active
June 30, 2020 05:11
-
-
Save humanscape-david/fb392dd76cac16e3bd18e7e91844eb86 to your computer and use it in GitHub Desktop.
매개 변수를 사용한 합성 예
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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