Last active
August 5, 2017 02:22
-
-
Save burhanloey/ecb8af9c16c616485d0ca7c14b023240 to your computer and use it in GitHub Desktop.
Constructing DSL to make readable Malay language sentence using Kotlin's extension functions
This file contains 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
package kotlinplayground | |
fun List<Int>.kemudian() = apply { } | |
fun List<Int>.dan() = apply { } | |
fun Int.sehingga(x: Int): IntRange = rangeTo(x) | |
fun diberiSenarai(x : IntRange): List<Int> = x.toList() | |
fun List<Int>.ambikNomborGanjil(): List<Int> = filter { it % 2 != 0 } | |
fun List<Int>.kaliDua(): List<Int> = map { it * 2 } | |
fun List<Int>.jumlahkan(): Int = sum() | |
fun main(args: Array<String>) { | |
val jawapan = diberiSenarai(1.sehingga(9)).ambikNomborGanjil().kemudian().kaliDua().dan().jumlahkan() | |
print(jawapan) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment