Created
October 17, 2018 21:49
-
-
Save libetl/a28e517ab20c7c0894adc62da0aa7dc9 to your computer and use it in GitHub Desktop.
simplest kotlin builder
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
fun main(args: Array<String>) { | |
val choosenMenu = menu { | |
fish | |
chips | |
hamburger | |
} | |
println(choosenMenu) | |
} | |
fun menu(init : MenuBuilder.() -> Unit) = MenuBuilder().apply(init).build() | |
data class Menu(val list: List<String>) | |
class MenuBuilder { | |
val list = mutableListOf<String>() | |
fun build () = Menu(list) | |
val hamburger : Unit get () {list += "Hamburger"} | |
val fish : Unit get () {list += "Fish"} | |
val chips : Unit get () {list += "Chips"} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment