List is ordered, Dict is not, so if you need to keep your elements sorted
for reasons other than fast lookup, lists win.

Also, if your main operation is iterating over your structure, lists will
be faster. Likewise if you need a stack, where you only push or pop from
the top.
On Sep 3, 2016 2:09 AM, "Simone Vittori" <[email protected]> wrote:

> I'm not an expert, but I'd say you should use a Dict whenever you have
> key-value data and you need insert, remove and/or query operations.
> You can always achieve the same with a List, but with a naive
> implementation you wouldn't get the same performance.
>
> I bet the TodoMVC uses a List for simplicity, especially towards
> beginners. A List is definitely simpler to understand than Dict at a first
> glance.
>
> On Saturday, 3 September 2016 09:28:04 UTC+1, Brian John Farrar wrote:
>>
>> I am looking for design guidelines on when to model a collection of
>> records as a Dict vs. a List.
>>
>> The TodoMVC uses a List, though at first glance a Dict seems like a more
>> natural match:
>> - There are several "id based" Msg's (ex. EditingEntry, UpdateEntry,
>> Delete, Check)
>> - Using Html.Keyed should be (slightly) easier to use
>>
>> But I think I understand why a List is more pragmatic.
>> In (my) practice, things get muddy attempting to implement TodoMVC with a
>> Dict.
>> Dict.update wants a (Maybe v -> Maybe v) resulting in nested case
>> statements which are okay but preferable to avoid.
>> (...it could be that my FP-fu is too weak to factor a concise expression.
>> Maybe.map doesn't appear useful as record updates aren't compose-able?)
>>
>> So, the "mapWhen" idiom (via an "updateEntry" helper) does seem to be the
>> simplest approach
>>
>> let
>>   updateEntry t =
>>        if ti.id = id then { t | field = newValue } else t
>> in
>>   { model | entries = List.map updateEntry model.entries }
>>
>> So if Dict isn't the best choice for a use case like TodoMVC...what kinds
>> of use cases is it good for?
>>
>>
>>
>> --
> 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.
>

-- 
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.

Reply via email to