-
Notifications
You must be signed in to change notification settings - Fork 0
Macros
Jonathan edited this page Mar 9, 2018
·
1 revision
TODO STUB
// func(T)* is a function that receives a value of type T
// and returns a tuple with * values.
macro <T> toTuple(receiver T, mapper: func(T)*): (_) = mapper(receiver)
macro <K, V> mapOf(pairs: ($:K = $:V (, $:K = $:V)*)): Map<K, V> {
val map = HashMap<K, V>()
for ((k, v) in pairs) map.put(k, v)
return map
}
val (name, age) = person.toTuple(_.name, _.age)
Expanded:
val name = person.name
val age = person.age
val map = mapOf("A" = "B", "C" = "D")
Expanded:
val map = HashMap<String, String>()
map.put("A", "B")
map.put("C", "D")