Skip to content
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
}

Expand

toTuple

val (name, age) = person.toTuple(_.name, _.age)

Expanded:

val name = person.name
val age = person.age

mapOf

val map = mapOf("A" = "B", "C" = "D")

Expanded:

val map = HashMap<String, String>()
map.put("A", "B")
map.put("C", "D")
Clone this wiki locally