Created
January 2, 2016 02:18
-
-
Save Jire/1c7c83a838960c9b97f4 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
fun main(args: Array<String>) { | |
val test = kton { | |
"1"..1 | |
"2" { | |
"3"..3 | |
"4" { | |
"5"..5 | |
} | |
} | |
"6" { | |
+{ | |
"7"..7 | |
"8"..8 | |
} | |
} | |
} | |
} | |
class KTON<T>(val body: KTON<*>.() -> T) { | |
val vars = HashMap<String, Any>() | |
val arrays = LinkedList<Any>() | |
operator fun get(key: String) = vars[key]!! | |
operator fun invoke(key: String) = get(key) as KTON<*> | |
operator fun <T : Any> String.rangeTo(value: T) { | |
vars[this] = value | |
} | |
operator fun String.invoke(body: KTON<*>.() -> Unit) { | |
vars[this] = kton(body) | |
} | |
operator fun <T> (KTON<*>.() -> T).unaryPlus() { | |
arrays.add(kton(this)) | |
} | |
operator fun get(index: Int) = arrays[index] as KTON<*> | |
} | |
fun <T> kton(body: KTON<*>.() -> T): KTON<T> { | |
val kton = KTON(body) | |
kton.body() | |
return kton | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment