Cindiary/elm-id/4.0.0

NOTE: the latest version is 7.1.0

ID.CounterDict

type alias CounterDict id value =
Dict Never id value

A dictionary with counter

Most of the functions in this module are a alias for the same function in ID.Dict, which can handle both 'ID.Dict' and 'ID.CounterDict'

empty : Counter (ID a) -> CounterDict (ID a) value

Create a empty CounterDict

singleton : Counter (ID a) -> value -> ( ID a, CounterDict (ID a) value )

Create a 'CounterDict' with a single ID-value pair

fromList : Counter (ID a) -> List value -> CounterDict (ID a) value

Create a new CounterDict from a list of values and assign an ID to every value

toList : CounterDict (ID a) value -> List ( ID a, value )

Convert a dictionary into an list of ID-value pairs, sorted by IDs.

isEmpty : CounterDict (ID a) value -> Bool

Determine if a dictionary is empty.

size : CounterDict (ID a) value -> Int

Determine the number of ID-value pairs in the dictionary.

member : ID a -> CounterDict (ID a) value -> Bool

Determine if a ID is in a dictionary.

get : ID a -> CounterDict (ID a) value -> Maybe value

Get the value associated with a ID. If the ID is not found, return Nothing.

getFrom : CounterDict (ID a) value -> ID a -> Maybe value

Same as get but with the arguments swapped, useful for pipelines.

add :
value
-> CounterDict (ID a) value
-> ( ID a, CounterDict (ID a) value )

Add a value to the Dictionary and assign it a new ID.

insert : ID a -> value -> CounterDict (ID a) value -> CounterDict (ID a) value

Insert a ID-value pair into a dictionary. Replaces value when there is a collision.

remove : ID a -> CounterDict (ID a) value -> CounterDict (ID a) value

Remove a ID-value pair from a dictionary. If the ID is not found, no changes are made.

ID a
-> (value -> value)
-> CounterDict (ID a) value
-> CounterDict (ID a) value

Update the value of a dictionary for a specific ID with a given function. If the ID is not found, no changes are made.

map : (ID a -> b -> c) -> CounterDict (ID a) b -> CounterDict (ID a) c

Apply a function to all values in a dictionary.

(ID a -> value -> Bool)
-> CounterDict (ID a) value
-> CounterDict (ID a) value

Keep only the ID-value pairs that pass the given test.

filterMap : (ID a -> b -> Maybe c) -> CounterDict (ID a) b -> CounterDict (ID a) c

Apply a function to all values in the dictionary and filter out the values that return Nothing.

fold : (ID a -> value -> c -> c) -> c -> CounterDict (ID a) value -> c

Fold over the ID-value pairs in a dictionary from lowest ID to highest ID.

ids : CounterDict (ID a) value -> List (ID a)

Get all of the IDs in a dictionary, sorted from lowest to highest.

values : CounterDict (ID a) value -> List value

Get all of the values in a dictionary, in the order of their IDs.

(ID a -> value -> Bool)
-> CounterDict (ID a) value
-> ( CounterDict (ID a) value, Dict (ID a) value )

Partition a dictionary according to some test. The first dictionary contains all ID-value pairs which passed the test, and the second contains the pairs that did not. The first dictionary retains the ID counter while the second is turned into a ID.Dict

CounterDict (ID a) b
-> Dict counter (ID a) c
-> CounterDict (ID a) b

Keep a ID-value pair when its ID does not appear in the second dictionary.

CounterDict (ID a) b
-> Dict counter (ID a) c
-> CounterDict (ID a) b

Keep a ID-value pair when its ID appears in the second dictionary. Preference is given to values in the first dictionary.

Dict counter (ID a) value
-> CounterDict (ID a) value
-> CounterDict (ID a) value

Combine two dictionaries. If there is a collision, preference is given to the first dictionary.

(ID a -> b -> c -> d)
-> CounterDict (ID a) b
-> Dict c2 (ID a) c
-> CounterDict (ID a) d

Apply a function to values that appear in both dictionaries and create a new dictionary with the results, values that don't appear in all dictionaries are skipped.

(ID a -> b -> c -> d -> e)
-> CounterDict (ID a) b
-> Dict c2 (ID a) c
-> Dict c3 (ID a) d
-> CounterDict (ID a) e

Same as ID.Dict.map2 but for 3 dictionaries

(ID a -> b -> c -> d -> e -> f)
-> CounterDict (ID a) b
-> Dict c2 (ID a) c
-> Dict c3 (ID a) d
-> Dict c4 (ID a) e
-> CounterDict (ID a) f

Same as ID.Dict.map2 but for 4 dictionaries

Json

encode : (value -> Value) -> CounterDict (ID id) value -> Value

Encode CounterDict to a JSON value

decoder : Decoder value -> Decoder (CounterDict (ID id) value)

JSON Decoder for `SetCounterDict