Great post … Could you clarify for me how the model gets passed into todoItemsSelector?
Thomas Shelton

Sure. I think the thing that cleared it up for me was this.

view : Model -> Html Msg
view =
todoItemsView << todoItemsSelector

If view had provided a model argument the way to read that is “view is a function that accepts a Model and returns Html Msg”.

However, if no argument is provided on line 2 then the way to read it is “view is a function that returns another function, which itself accepts a Model and returns Html Msg”.

As for the actual function composition the docs for >> are helpful.

Consider this example:

sqrt >> isEven >> not
-- or
not << isEven << sqrt

These two statements do the same thing. What’s happening is the output from one function is sent as input to the next function, and a new function is returned that does all of that for you. So the above code returns a function that tells you if the square root of a number is odd.

todoItemsView << todoItemsSelector

Similarly, the output of todoItemsSelector is used as input for todoItemsView.

Let’s take a look at their type annotations:

todoItemsView : ViewModel -> Html Msg
todoItemsSelector : Model -> ViewModel

When function composition is used to combine these two a new function is created that takes in a Model, that Model is sent to todoItemsSelector and transformed to a ViewModel. Then that ViewModel is sent to todoItemsView and Html Msg is returned.

That new function could be annotated with Model -> Html Msg which is exactly what the view function says it returns.

I hope that helps.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.