Cindiary/elm-id/2.0.0

NOTE: the latest version is 7.1.0

ID.Counter

type alias Counter id =
Counter id

Counter type which is used to create ID values

new : a -> Counter (ID a)

Create a new counter

newID : Counter (ID a) -> ( ID a, Counter (ID a) )

Creates a new ID and advanced the counter, make sure to use the new counter to create any new IDs

newID2 : Counter (ID a) -> ( ID a, ID a, Counter (ID a) )

Same as newID but creates 2 IDs instead of 1

Counter (ID a)
-> ( { id1 : ID a
, id2 : ID a
, id3 : ID a
}
, Counter (ID a)
)

Same as newID but creates 3 IDs instead of 1

Counter (ID a)
-> ( { id1 : ID a
, id2 : ID a
, id3 : ID a
, id4 : ID a
}
, Counter (ID a)
)

Same as newID but creates 4 IDs instead of 1

(ID a -> b -> c)
-> Counter (ID a)
-> List b
-> ( List c, Counter (ID a) )

Assign IDs to a number of values, make sure to use the new counter to create any new IDs

accountForIDs : List (ID a) -> Counter (ID a) -> Counter (ID a)

Account for a list of IDs. This should not be necessary if you always make sure to use the counter result from newID, but can be used to sanitize the counter after encoding and decoding a counter and values

accountForItemIDs : (item -> ID a) -> List item -> Counter (ID a) -> Counter (ID a)

Same as accountForIDs but can be used for a list of values containing an ID

newCounter = accountForItemIDs .id users counter
accountForDictIDs : Dict counter (ID a) value -> Counter (ID a) -> Counter (ID a)

Same as accountForIDs but can be used with a Dict

(val -> ID a)
-> (val -> ID a -> val)
-> List val
-> Counter (ID a)
-> ( List val, Counter (ID a) )

Account for all used IDs in the counter (as in accountForIDs) and give new IDs to any items that have a duplicate ID

Json

encode : Counter id -> Value

Encode 'Counter' to a JSON value

decoder : Decoder (Counter id)

JSON Decoder for 'Counter'