Thanks for the reply...
On Tuesday, October 11, 2016 at 4:36:47 AM UTC-7, Wouter In t Velt wrote:
>
> The comparison page you refer to is more a high-level comparison between
> javascript and elm syntax.
> It does not look like it is intended to be in-depth.
>
> I agree it would be useful to have some docs at some time summing up the
> pros and cons of List vs Array vs Set vs Dict.
> But I am not sure that the "From javascript" place would be the right
> place.
>
>
I agree that "javascript" is probably not the best place. However, as a
newcomer, it is a place I studied a lot to get a feel for how to translate
idioms I know from JS into Elm.
> PS: Getting an item from index in a List in Elm is quite straightforward
>
> getFromList : Int -> List a -> Maybe a
> getFromList index someList =
> List.head <| List.drop index someList
>
> The main consideration vs Array or Dict (I think) is performance when the
> lists get larger.
>
>
Thanks, that is cool. And clearly "straightforward" is in the eye of the
beholder. 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.
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). The update gets the
index as so:
DetectorPlotVars ->
let
pvars = Array.get index model.detectorPlotVars
in
case pvars of
Just pvars ->
let
toggle = {pvars | on = not pvars.on}
newArr = Array.set index toggle model.detectorPlotVars
in
({model | detectorPlotVars = newArr}
, getColorJson {model | detectorPlotVars = newArr})
_ -> (model, Cmd.none)
Please note that this will return a Maybe type (same as Array, and Dict BTW)
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.