Actually, additions (and updates where you're changing cross-references, 
obviously) would require updating the cross references, as well.

Still, this is much more optimized for additions, updates, and deletions, 
and much less error prone than, say, doing a linear scan through any number 
of lists that might contain a reference to your record.

On Saturday, September 24, 2016 at 4:11:51 PM UTC-4, Spencer Judd wrote:
>
> I tend to model things like this with Dicts, Sets, and a type alias for 
> each identifier. So, something like
>
> type alias Model =
>   { artists : Dict ArtistId Artist
>   , albums : Dict AlbumId Album
>   }
>
>
> type alias ArtistId =
>   Int
>
>
> type alias Artist =
>   { id : ArtistId
>   , name : String
>   , albums : Set AlbumId
>   }
>
>
> type alias AlbumId =
>   Int
>
>
> type alias Album =
>   { id : AlbumId
>   , name : String
>   , artists : Set ArtistId
>   }
>
> This is optimized for querying, adding and updating both Artists and 
> Albums. Deletions require a bit more thought: You'll have to update all the 
> cross-reference Set's as well.
>
> On Thursday, September 22, 2016 at 6:24:38 PM UTC-4, Dénes Harmath wrote:
>>
>> Hi everybody,
>>
>> in a typical model, there are cross-references: e.g. we have artists and 
>> albums, and the album refers to its artist. How do we model this in Elm? A 
>> possible approach is giving unique identifiers to objects and store the 
>> referred object's identifiers similar to the TodoMVC example - is this 
>> mechanism extracted to some library in a type-safe way?
>>
>> Thank you in advance,
>> thSoft
>>
>

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