raulraja

    raulraja

    2 years ago
    A leaner
    Tuple
    runtime with type proofs and automatic conversions coming up in Arrow Meta
    drieks

    drieks

    2 years ago
    Why not this way?
    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)
    raulraja

    raulraja

    2 years ago
    That's an option and Person.tupled can also be inlined
    drieks

    drieks

    2 years ago
    @tupled
    data class Person(val name: String, val age: Int)
    could generate:
    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)
    }
    raulraja

    raulraja

    2 years ago
    yes, that is our plan in arrow.generic and other places, the proofs are automatically generated for all data classes