Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created July 31, 2019 06:44
Show Gist options
  • Save ch8n/7a8e1720134a4c82a30305b8c3b64e04 to your computer and use it in GitHub Desktop.
Save ch8n/7a8e1720134a4c82a30305b8c3b64e04 to your computer and use it in GitHub Desktop.
//initally
data class Items(val one: Int, val two: Int, val three: Int)
val item = Items(1,2,3)
// destructing
val (one, two) = item.run { arrayOf(one, two) } // Enforcing position destructing
println("$one $two")
//after refactor
data class Items(val one: Int, val two: Int, val three: Int,val four:Int)
val item = Items(1,2,3,4)
// no error in destructing for wrong values
val (one, two) = item.run { arrayOf(one, two) } // Enforcing position destructing
println("$one $two")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment