There have been several recent questions on the elm-discuss mailing list about decoding large JSON objects.
The problem: Elm’s decoders provide for decoding objects with up to 8 fields, but what happens when you need more?
The solution here is, unfortunately, not super obvious.
Last time we talked about using
|> allow you to create pipelines through with data can flow (like water.)
That’s all well and good, but what if you need pipes without the water?
Well, that’s easy enough to do with function composition!
Say you’ve got a bunch of functions, and you want to use them together.
This is a common situation, but it can get a little… messy.
Let’s take an example from the Elm docs:
scale 2 (move (10,10) (filled blue (ngon 5 30)))
This is, well, just OK.
A little parentheses go a long way, but this is just unclear.
You have to follow them very closely to figure out the evaluation order.
Editor highlighting can help, but wouldn’t it be better to get rid of the problem?
But how do we do that?
Elm is usually pretty clear, but there are certain things that are a little hard to search for.
One of those is the
! operator, introduced in 0.17.
What does it do?
Where does it come from?
And even more important, when should you use it?
When you’re building an app with Elm, you’ll find a common problem: where do you
put shared state in models? Let’s take selecting an item for viewing as an
example. You’ll start out having a model field with a selected item and one with
a collection. But that’s duplication! How do you keep the model state in sync
when one side has to change?