Help understanding destructuring part of SPA example

I’m a beginner and very new to Elm’s syntax. I saw this piece of code in the real world SPA example:

The destructuring part is what is confusing me — I know that this is valid:

(x, y) = (1, 2)

But the expression from the elm spa code is assigning 6 variables: toPage, toModel, toMsg, subUpdate, subMsg and subModel from what it seems to be a two element tuple (model, cmd).

Isn’t this invalid? How does it work, what am I missing?

That’s just a local function via the let binding, down in the code toPage gets called with the 5 arguments and it just returns the 2-tuple. You could move that function out as a toplevel function of the module.

Yep, if it were really trying to assign to those 6 variables using destructing the code (vs being a function definition) it would look like this:

(toPage, toModel, toMsg, subUpdate, subMsg, subModel) = …

… which would not be very future proof with the 3 element tuple restriction coming in 0.19 :slight_smile:

Ahhh, okay, makes sense! Thanks @mfeineis @nathanbraun !

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.