Op dinsdag 11 oktober 2016 23:36:49 UTC+2 schreef J. E. Marca:
> On first read I laughed out loud --- I don't know what <| does, and it 
> seems a random application of head and drop.  Reading closer, it *is* 
> straightforward as you say... drop first n items (one based count), then 
> get the next one (via List.head) and return that (which ends up being the 
> traditional zero based index count).  Clever, but not something I can come 
> up with on my own.  

Touché! my background is also in javascript (React + Flux). For me all the 
"|>" "<|" ">>" symbols where confusing at first as well. I guess I am 
already used to them :)

> Regardless, I wanted to *assign* to that element in the update loop, so 
> Array works better for me.  This is what I'm doing.  My view has a bunch of 
> buttons that onClick send a message and an index.  (The index value is 
> built into the html element via  Array.indexedMap).  

I pattern that I took with me from javascript as well is similar to your 

   - Get one item from some collection (Array)
   - Apply a change function the item = make a new item
   - Put the new item back in the collection = make new collection with 
   updated item

But I ended up with a lot of "case someMaybe of" etcetera, and a lot of 
code lines.

What I do nowadays is different: pass an index + a change function to a 
collection, and get back the whole collection with the updated item in it.
has an Array.update function which allows you to do that.

Note however, that with Array.update, you do not know *if *an update has 
taken place, you just get the new Array back.
So the example below is slightly different from your original, because it 
will also call the getColorJson if the pvars did not change.
DetectorPlotVars ->
        changePvars pvars = { pvars | on = not pvars.on }  -- 
local function that takes pvar and toggles "on" parameter

        newArr = Array.update index changePVars model.detectorPlotVars

        newModel = { model | detectorPlotVars = newArr }
        ( newModel
        , getColorJson newModel 

You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to