I am looking for a clean way to create destructurable objects in-line. kotlin.Pair
and kotlin.Triple
cover a lot of use cases, but sometimes there are more objects that are needed to be passed.
One sample use case is RX's zip
function, where the results of several I/O calls need to be mapped into another object:
Single
.zip(repositoryA.loadData(someId),
repositoryB.loadData(someId),
repositoryC.loadAll(),
repositoryD.loadAll()),
{ objectA, objectB, objectsC, objectsD -> /*some Kotlin magic*/ }
)
.map { (objectA, objectB, objectsC, objectsD) -> /*do the mapping*/ }
I am trying to figure out what would go in the "some Kotlin magic" part. If there were only 3 repositories, it would be
Triple(objectA, objectB, objectsC)
Do I need to create a new data class for this, and for any n-tuple case, or is there another way?