Chadtech/id/4.1.0

NOTE: the latest version is 4.2.0

Db

A way of storing your data by Id

Db

type Db item

Short for "Database", it stores data by unique identifiers

empty : Db item

An empty Db with no entries

toDict : Db item -> Dict String item

turn a Db item into a Dict String item

List

fromList : List ( Id, item ) -> Db item

Initialize a Db from a list of id-value pairs

toList : Db item -> List ( Id, item )

Turn your Db into a list

Helpers

insert : Id -> item -> Db item -> Db item

Insert an item into the Db under the given Id

insertMany : List ( Id, item ) -> Db item -> Db item

Insert many items into the Db under their given Ids

get : Db item -> Id -> Maybe item

Get the item under the provided Id

getWithId : Db item -> Id -> ( Id, Maybe item )

Just like get, except it comes with the Id, for those cases where you dont want the item separated from its Id

getMany : Db item -> List Id -> List item

Get many items from a Db from a list of Ids. Elements not in the Db simply wont appear in the return result.

getManyWithId : Db item -> List Id -> List ( Id, Maybe item )

Get many items from a Db, but dont filter out missing results, and pair results with their Id

remove : Id -> Db item -> Db item

Remove the item at the given Id, if it exists

update : Id -> (Maybe item -> Maybe item) -> Db item -> Db item

Update an item in a Db, using an update function. If the item doesnt exist in the Db, it comes into the update as Nothing. If a Nothing comes out of the update function, the value under that id will be removed.

map : (a -> b) -> Db a -> Db b

Map a Db to a different data type.

mapItem : Id -> (item -> item) -> Db item -> Db item

Apply a change to just one item in the Db, assuming the item is in the Db in the first place. This function is just like update except deleting the item is not possible.