Cindiary/elm-id/6.0.0

NOTE: the latest version is 7.1.0

Id.CounterList

type CounterList id value

A list with a id counter

Most of the functions in this module are a alias for the same function in Id.List, which can handle both 'Id.List' and 'CounterList'

empty : Counter (Id a) -> CounterList (Id a) value

Create a empty CounterList

singleton : Counter (Id a) -> value -> ( Id a, CounterList (Id a) value )

Create a 'CounterList' with a single Id-value pair

fromList : Counter (Id a) -> List value -> CounterList (Id a) value

Create a new CounterList from a list of values and assign an Id to every value

fromIdList : Counter (Id a) -> List (Id a) value -> CounterList (Id a) value

Create a new CounterList from a list of Id-value pairs. This removes pairs with duplicate Ids

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

Get the counter from a counter list

toList : CounterList id value -> List id value

Convert a CounterList into a Id.List.

isEmpty : CounterList (Id a) value -> Bool

Determine if a list is empty.

length : CounterList (Id a) value -> Int

Determine the number of Id-value pairs in the list.

member : Id a -> CounterList (Id a) value -> Bool

Determine if a Id is in a list.

get : Id a -> CounterList (Id a) value -> Maybe value

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

getFrom : CounterList (Id a) value -> Id a -> Maybe value

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

add :
value
-> CounterList (Id a) value
-> ( Id a, CounterList (Id a) value )

Add a value to the List and assign it a new Id.

addInto : value -> CounterList (Id a) value -> CounterList (Id a) value

Same as as add but only returns the List

Int
-> value
-> CounterList (Id a) value
-> ( Id a, CounterList (Id a) value )

Add a value to the List, assign it a new Id and insert it at a given index. Indexes lower than 0 will be inserted at index 0. Indexes higher than the length of the list will inserted at the end of the list.

addList : List value -> CounterList (Id a) value -> CounterList (Id a) value

Add a list of values to the List and assign them Ids

insert : Id a -> value -> CounterList (Id a) value -> CounterList (Id a) value

Insert a Id-value pair into a list. If there is a existing pair with the same Id if will be replaced. If there isn't a existing pair the pair will be inserted at the start of the list.

Int
-> Id a
-> value
-> CounterList (Id a) value
-> CounterList (Id a) value

Insert a Id-value pair into a given index into a Id.List. This will remove any existing value with the same Id. Indexes lower than 0 will be inserted at index 0. Indexes higher than the length of the list will inserted at the end of the list.

move : Id a -> Int -> CounterList (Id a) value -> CounterList (Id a) value

Move a existing value to a new index. Does nothing if the item is not present.

remove : Id a -> CounterList (Id a) value -> CounterList (Id a) value

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

Id a
-> (value -> value)
-> CounterList (Id a) value
-> CounterList (Id a) value

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

map : (Id a -> b -> c) -> CounterList (Id a) b -> CounterList (Id a) c

Apply a function to all values in a list.

(Id a -> value -> Bool)
-> CounterList (Id a) value
-> CounterList (Id a) value

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

filterMap : (Id a -> b -> Maybe c) -> CounterList (Id a) b -> CounterList (Id a) c

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

foldl : (Id a -> value -> c -> c) -> c -> CounterList (Id a) value -> c

Fold over the Id-value pairs in a list from left to right.

foldr : (Id a -> value -> c -> c) -> c -> CounterList (Id a) value -> c

Fold over the Id-value pairs in a list from right to left.

ids : CounterList (Id a) value -> List (Id a)

Get all of the Ids in a list, sorted from lowest to highest.

values : CounterList (Id a) value -> List value

Get all of the values in a list, in the order of their Ids.

(id -> value -> Bool)
-> CounterList id value
-> ( CounterList id value, List id value )

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

diff : CounterList id b -> List id c -> CounterList id b

Keep a Id-value pair when its Id does not appear in the second list.

intersect : CounterList id b -> List id c -> CounterList id b

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

List (Id a) value
-> CounterList (Id a) value
-> CounterList (Id a) value

Combine two Lists. If there is a collision, preference is given to the first List.

unzip : CounterList id ( a, b ) -> ( CounterList id a, List id b )

Decompose a list of tuples into a tuple of lists.

Json

encode : (value -> Value) -> CounterList (Id id) value -> Value

Encode CounterList to a JSON value

decoder : Decoder value -> Decoder (CounterList (Id id) value)

JSON Decoder for `SetCounterList