https://kotlinlang.org logo
#arrow-meta
Title
# arrow-meta
r

raulraja

11/18/2019, 8:58 AM
A leaner
Tuple
runtime with type proofs and automatic conversions coming up in Arrow Meta
👍 1
d

drieks

11/18/2019, 9:27 AM
Why not this way?
Copy code
inline fun <A, B> tupled(a: A, b: B): Tupel2<A, B> =
  Tupled(arrayOf(name, age)).widen()

fun Person.tupled(): Tuple2<String, Int> = tupled(name, age)
r

raulraja

11/18/2019, 1:26 PM
That's an option and Person.tupled can also be inlined
d

drieks

11/19/2019, 7:00 AM
Copy code
@tupled
data class Person(val name: String, val age: Int)
could generate:
Copy code
typealias TupleForPerson = Tupel2<String, Int>

@proof(conversion = true)
inline fun Person.tupled(): TupleForPerson =   tupled(name, age)

@proof(conversion = true)
inline fun TupleForPerson.person(): Person {
  val (name, age) = this
  return Person(name, age)
}
r

raulraja

11/19/2019, 9:51 AM
yes, that is our plan in arrow.generic and other places, the proofs are automatically generated for all data classes
🙂 1
4 Views