Cindiary/elm-id/5.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

getCounter : a -> CounterDict (Id a) value -> Counter (Id a)

Get the counter from a counter dict

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

Convert a dictionary into an list of Id-value pairs, sorted by Ids.

toDict : CounterDict id value -> Dict id value

Convert a CounterDict into a regular Id.Dict

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