Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data KVITable v = KVITable KeyVals (Key -> KeyVal) (Map KeySpec v) Text
- type Key = Text
- type KeyVal = Text
- type KeyVals = [(Key, [KeyVal])]
- type KeySpec = [(Key, KeyVal)]
- fromList :: [Item (KVITable v)] -> KVITable v
- toList :: KVITable v -> [Item (KVITable v)]
- lookup :: KeySpec -> KVITable v -> Maybe v
- keyVals :: Lens' (KVITable v) KeyVals
- keyValGen :: Lens' (KVITable v) (Key -> KeyVal)
- valueColName :: Lens' (KVITable v) Text
- insert :: KeySpec -> v -> KVITable v -> KVITable v
- foldlInsert :: KVITable v -> (KeySpec, v) -> KVITable v
- filter :: ((KeySpec, v) -> Bool) -> KVITable v -> KVITable v
- adjust :: (v -> v) -> KeySpec -> KVITable v -> KVITable v
- adjustWithKey :: (KeySpec -> v -> v) -> KeySpec -> KVITable v -> KVITable v
- delete :: KeySpec -> KVITable v -> KVITable v
- update :: (v -> Maybe v) -> KeySpec -> KVITable v -> KVITable v
- updateWithKey :: (KeySpec -> v -> Maybe v) -> KeySpec -> KVITable v -> KVITable v
- rows :: KVITable v -> [([KeyVal], v)]
Documentation
The core KeyValue Indexed Table. This table is similar to a Map, but the values are indexed by a list of Key+Value combinations, and the table contents can be sparse.
Instances
Foldable KVITable Source # | |
Defined in Data.KVITable fold :: Monoid m => KVITable m -> m # foldMap :: Monoid m => (a -> m) -> KVITable a -> m # foldMap' :: Monoid m => (a -> m) -> KVITable a -> m # foldr :: (a -> b -> b) -> b -> KVITable a -> b # foldr' :: (a -> b -> b) -> b -> KVITable a -> b # foldl :: (b -> a -> b) -> b -> KVITable a -> b # foldl' :: (b -> a -> b) -> b -> KVITable a -> b # foldr1 :: (a -> a -> a) -> KVITable a -> a # foldl1 :: (a -> a -> a) -> KVITable a -> a # elem :: Eq a => a -> KVITable a -> Bool # maximum :: Ord a => KVITable a -> a # minimum :: Ord a => KVITable a -> a # | |
Traversable KVITable Source # | |
Functor KVITable Source # | |
Monoid (KVITable v) Source # | |
Semigroup (KVITable v) Source # | The KVITable semigroup is left biased (same as Data.Map). Note that joining tables can result in a table that has a different keyVals sequence than either input table. |
IsList (KVITable v) Source # | |
Show v => Show (KVITable v) Source # | |
Eq v => Eq (KVITable v) Source # | |
type Item (KVITable v) Source # | |
Defined in Data.KVITable |
type KeyVals = [(Key, [KeyVal])] Source #
The KeyVals
specifies all valid values for a particular Key
in the KVITable
. The set of KeyVals
can be provided at the
initialization of the KVITable
to ensure specific values are
considered (especially if rendering includes blank rows or
columns); if entries are added to the table with a KeyVal
previously unknown for the Key
, the KeyVals
for the table is
automatically updated to include the new KeyVal
.
fromList :: [Item (KVITable v)] -> KVITable v Source #
Converts a list of ([(Key,Val)], Value)
tuples to a KVI table.
toList :: KVITable v -> [Item (KVITable v)] Source #
Converts a KVI table to a list of ([(Key,Val)], Value)
tuples.
lookup :: KeySpec -> KVITable v -> Maybe v Source #
Retrieve an entry from the KVITable given a keyspec. The keyspec may be minimally specified (i.e. it does not need to contain keys whose value is the default key value) and it may present the keys out of order and the lookup will still succeed (if there is a value for the normalized keyspec), but it will be faster to use the normalized key directly.
keyVals :: Lens' (KVITable v) KeyVals Source #
Fetch or set the keyvals list via lenses. Note that setting the keyval list will drop any current contents in the table that do not have entries in the keyvals list.
valueColName :: Lens' (KVITable v) Text Source #
Fetch or set the column name for the actual value cell in the
KVITable
.
insert :: KeySpec -> v -> KVITable v -> KVITable v Source #
Inserts a new cell value into the table at the specified keyspec location. The keyspec may be minimally specified and out-of-order.
This may be an expensive operation if it has to extend the keyvals for the table. In general, insertion is expected to be less frequent than lookups so computation costs are biased towards the insertion operation.
foldlInsert :: KVITable v -> (KeySpec, v) -> KVITable v Source #
The foldlInsert is a convenience function that can be specified as the function argument of a foldl operation over the list form of a KVITable to generate the associated KVITable.
filter :: ((KeySpec, v) -> Bool) -> KVITable v -> KVITable v Source #
Filter KVITable
to retain only the elements that satisfy some predicate.
adjust :: (v -> v) -> KeySpec -> KVITable v -> KVITable v Source #
Adjust a value at the specified keyspec; return the original
KVITable
if that keyspec is not found in the table.
adjustWithKey :: (KeySpec -> v -> v) -> KeySpec -> KVITable v -> KVITable v Source #
Adjust a value at the specified keyspec; return the original
KVITable
if that keyspec is not found in the table.
delete :: KeySpec -> KVITable v -> KVITable v Source #
Delete the value at the specified keyspec location in the
KVITable
. If the keyspec does not exist, the original table is
returned.
update :: (v -> Maybe v) -> KeySpec -> KVITable v -> KVITable v Source #
Update the KVITable
to remove or set a new value for the
specified entry if the updating function returns Nothing
or Just
v
, respectively. The update function is passed the value for the
keyspec to be updated. If the value does not exist in the table,
the original table is returned.
updateWithKey :: (KeySpec -> v -> Maybe v) -> KeySpec -> KVITable v -> KVITable v Source #
Update the KVITable
to remove or set a new value for the
specified entry if the updating function returns Nothing
or Just
v
, respectively. The update function is passed both the keyspec
and the current value at that key. If the value does not exist in
the table, the original table is returned.