Skip to content
Jonathan edited this page Mar 9, 2018 · 1 revision
fun toIter(str: String): (Iter<Char>, String) = ...
fun get(): (Long, String, LocalDate) = ...

Also you may use named generics:

fun get(): (id: Long, name: String, birthDate: LocalDate) = ...

Also Firefly provides a toTuple macro to transform objects into tuples:

user.toTuple(_.id, _.name, _.birthDate)

Named tuples

Tuples with named generics may be accessed by names instead of by _.0, _.1, etc:

fun get(): (id: Long, name: String, birthDate: LocalDate) = ...

val get = get()

get.id
get.name
get.birthDate

// Or using expansion:

val (_) = get()

id
name
birthDate

Destruction

Destructurable types may be destructed to tuples:

val (name, birthDate) = user

Also if type is not Destructurable, then you could use toTuple:

val (name, birthDate) = user.toTuple(_.name, _.birthDate)

Clone this wiki locally