Search code examples
f#tuplesiterable-unpacking

Unpack tuple into another tuple


Suppose I need to construct a tuple of length three:

(x , y, z)

And I have a function which returns a tuple of length two - exampleFunction and the last two elements of the tuple to be constructed are from this tuple.

How can I do this without having to call the exampleFunction two times:

(x, fst exampleFunction , snd exampleFunction)

I just want to do / achieve something like

(x, exampleFunction)

but it complains that the tuples have unmatched length ( of course )

Not looking at doing let y,z = exampleFunction()


Solution

  • There may be a built in function, but a custom one would work just as well.

    let repack (a,(b,c)) = (a,b,c)
    repack (x,exampleFunction)