Recomposition feature

I would like receive your comment about “recomposition” feature, an inversion for data class composition.

Moreover same principle may be applied to spread operator and recompose an array, a list or a map.

    data class Point(val x:Int, val y:Int)

    fun main(args: Array<String>) {
        // data classes proposal
        // proposal 1
        val p0 = Point(0,0) // val (x0, y0) = p0
        val p1 : Point = (0, 1)

        // data structures proposal
        // proposal 2
        val pointArray1 = arrayOf( p0, p1, Point(1, 1) )
        val pointArray2 : Array<Point> = [ p0, p1, (1, 1) ]

        // proposal 3
        val pointList1 = listOf( p0, p1, Point(1, 1) )
        val pointList2 : List<Point> = [ p0, p1, (1, 1) ]

        // proposal 4
        val pointMap1 = mapOf( p0 to "origin", p1 to "other", Point(1, 1) to "upper")
        val pointMap2 : Map<Point, String> = [ p0 to "origin", p1 to "other", (1, 1) to "upper" ]
    }
4 Likes

I think it’s natural to think about something along these lines. There’d be a lot of particular details to be worked out before we could asses this as a candidate language feature

1 Like