The code doesn’t intend to create n-tuples instead and
creates nested pairs (2-tuple). As we conveniently can create nested pairs I would like a convenient way to deconstruct them.
A “trick” to avoid nested tuples is to implement the Applicative functional pattern but that relies on partial functions which AFAIK kotlin doesn’t support.
What I can do in kotlin to fix the code above is creating a bunch of overloads for combinations of 1,2,3,4,5 … N results. (Like in C++ before variadic templates but unlike C++ we don’t have macros that simplify creating the overloads).
I agree that deconstruction as is today in kotlin only really makes good sense when dealing with tuples. If one supports nested tuples (like pairs) it make sense to me to support nested deconstruction of those.
With that said in ML like languages nested deconstruction is also used in pattern matching for union types and tuples and is very useful there.