A Dict data structure that derives keys from values. The keys can be any comparable
type. This includes Int, Float, Time, Char, String, and tuples or
lists of comparable types.
Since it uses the underlying core/Dict module, insert, remove, and query operations all take O(log n) time.
Create an indexed dictionary from list by providing a key fn.
users : IxDict.IxDict String User
users =
IxDict.fromListBy .id
[ User "alice" "Alice"
, User "bob" "Bob"
]
type alias User =
{ id : String, name : String }
updated : IxDict.IxDict String User
updated =
users
|> IxDict.insert (User "charlie" "Charlie")
|> IxDict.remove "bob"Create an indexed dictionary from a normal dictionary by providing a key fn. Esentially gets the dict values and uses fromListBy:
fromDictBy : (v -> comparable) -> Dict k v -> IxDict comparable v
fromDictBy keyFn =
fromListBy keyFn << Dict.valuesSee fromListBy on how to use it.
Create a dictionary with one key-value pair and a keyFn
Insert a value into an indexed dictionary. Replaces value when there is a collision.
Remove a key-value pair from the dictionary. If the key is not found, no changes are made.
Determine if a value is in a dictionary, only by comparing keys.
Determine if a value is structually in a dictionary.
Convert a dictionary into an association list of key-value pairs, sorted by keys.
Map a function onto a ixDict, creating a new ixDict with no duplicates.
This operation is not structure-preserving for sets, so is not a valid Functor. An example case: mapping const x over a ixDict with n > 0 elements will result in a ixDict with one element.
Transform values and rebuild the dict with a new keyFn
Fold over the key-value pairs in an indexed dictionary from lowest key to highest key.
Fold over the key-value pairs in an indexed dictionary from highest key to lowest key.
Filter... use keep or reject instead.
Because, what does it filter? Do you want the filtered product like coffee (in this case, use reject) or the remaining good part like gold pannig (in this case, use keep)
Keep only the key-value pairs that pass the given test.
Reject all key-value pairs that for a given test
Partition an indexed dictionary according to some test. The first dictionary contains all key-value pairs which passed the test, and the second contains the pairs that did not.
Combine two indexed dictionaries. If there is a collision, preference is given to the first indexed dictionary.
Keep a key-value pair when its key appears in the second indexed dictionary. Preference is given to values in the first indexed dictionary.
Keep a key-value pair when its key does not appear in the second indexed dictionary.
Uses Tuple.first as keyFn
Uses .id as keyFn
Uses Tuple.first as keyFn
Uses .id as keyFn
A dictionary of keys and values wrapped with a keyFn
(v -> k)to derive keys from that dictionary.