Copyright | (c) gspia 2020- |
---|---|

License | BSD |

Maintainer | gspia |

Safe Haskell | Safe |

Language | Haskell2010 |

# Fcf.Data.MapC

MapC provides an interface to mapping keys to values, which is similar to that given by the containers-package. Note that the this module still misses some of the methods that can be found in containers. If you need some, please do open up an issue or better, make a PR.

Many of the examples are from containers-package.

We call this MapC because name Map is reserved to the map-function in Fcf-package. The internal representation is type-level list. We hope that one day the internal representation is based on balanced trees similar to the one used in the containers.

## Synopsis

- data MapC k v = MapC [(k, v)]
- data Null :: MapC k v -> Exp Bool
- data Size :: MapC k v -> Exp Nat
- data Lookup :: k -> MapC k v -> Exp (Maybe v)
- data Member :: k -> MapC k v -> Exp Bool
- data NotMember :: k -> MapC k v -> Exp Bool
- data Disjoint :: MapC k v -> MapC k v -> Exp Bool
- data Elems :: MapC k v -> Exp [v]
- data Keys :: MapC k v -> Exp [k]
- data Assocs :: MapC k v -> Exp [(k, v)]
- data Empty :: Exp (MapC k v)
- data Singleton :: k -> v -> Exp (MapC k v)
- data Insert :: k -> v -> MapC k v -> Exp (MapC k v)
- data InsertWith :: (v -> v -> Exp v) -> k -> v -> MapC k v -> Exp (MapC k v)
- data Delete :: k -> MapC k v -> Exp (MapC k v)
- data Union :: MapC k v -> MapC k v -> Exp (MapC k v)
- data Difference :: MapC k v -> MapC k v -> Exp (MapC k v)
- data Intersection :: MapC k v -> MapC k v -> Exp (MapC k v)
- data Adjust :: (v -> Exp v) -> k -> MapC k v -> Exp (MapC k v)
- data Map :: (v -> Exp w) -> MapC k v -> Exp (MapC k w)
- data MapWithKey :: (k -> v -> Exp w) -> MapC k v -> Exp (MapC k w)
- data Foldr :: (v -> w -> Exp w) -> w -> MapC k v -> Exp w
- data Filter :: (v -> Exp Bool) -> MapC k v -> Exp (MapC k v)
- data FilterWithKey :: (k -> v -> Exp Bool) -> MapC k v -> Exp (MapC k v)
- data Partition :: (v -> Exp Bool) -> MapC k v -> Exp (MapC k v, MapC k v)
- data FromList :: [(k, v)] -> Exp (MapC k v)
- data ToList :: MapC k v -> Exp [(k, v)]

# MapC type

A type corresponding to Map in the containers. We call this MapC because name Map is reserved to the map-function in Fcf-package.

The representation is based on type-level lists. Please, do not use that fact but rather use the exposed API. (We hope to change the internal data type to balanced tree similar to the one used in containers. See TODO.md.)

MapC [(k, v)] |

## Instances

type Eval (Empty :: MapC k v -> Type) Source # | |

type Eval (FromList lst :: MapC k v -> Type) Source # | |

type Eval (Partition f (MapC lst) :: (MapC k v, MapC k v) -> Type) Source # | |

type Eval (Singleton k2 v2 :: MapC k1 v1 -> Type) Source # | |

type Eval (Delete k2 (MapC lst) :: MapC k1 v -> Type) Source # | |

type Eval (Union (MapC lst1) (MapC lst2) :: MapC k v -> Type) Source # | |

type Eval (Filter f (MapC lst) :: MapC k v -> Type) Source # | |

type Eval (FilterWithKey f (MapC lst) :: MapC k v -> Type) Source # | |

Defined in Fcf.Data.MapC | |

type Eval (Intersection mp1 mp2 :: MapC k v -> Type) Source # | |

Defined in Fcf.Data.MapC | |

type Eval (Difference mp1 mp2 :: MapC k v -> Type) Source # | |

Defined in Fcf.Data.MapC | |

type Eval (Insert k2 v2 (MapC lst) :: MapC k1 v1 -> Type) Source # | |

type Eval (Adjust f k2 (MapC lst) :: MapC k1 v -> Type) Source # | |

type Eval (MapWithKey f mp :: MapC k v2 -> Type) Source # | |

Defined in Fcf.Data.MapC | |

type Eval (Map f mp :: MapC k v2 -> Type) Source # | |

type Eval (InsertWith f k2 v2 (MapC lst) :: MapC k1 v1 -> Type) Source # | |

Defined in Fcf.Data.MapC |

# Query

data Null :: MapC k v -> Exp Bool Source #

Null

### Example

`>>>`

Eval (Null =<< FromList '[ '(5,"a"), '(3,"b")]) :: Bool = 'False`:kind! Eval (Null =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (Null =<< Empty) :: Bool = 'True`:kind! Eval (Null =<< Empty)`

data Size :: MapC k v -> Exp Nat Source #

Size

### Example

`>>>`

Eval (Size =<< FromList '[ '(5,"a"), '(3,"b")]) :: Nat = 2`:kind! Eval (Size =<< FromList '[ '(5,"a"), '(3,"b")])`

data Lookup :: k -> MapC k v -> Exp (Maybe v) Source #

Lookup

### Example

`>>>`

Eval (Lookup 5 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Maybe Symbol = 'Just "a"`:kind! Eval (Lookup 5 =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (Lookup 7 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Maybe Symbol = 'Nothing`:kind! Eval (Lookup 7 =<< FromList '[ '(5,"a"), '(3,"b")])`

data Member :: k -> MapC k v -> Exp Bool Source #

Member

### Example

`>>>`

Eval (Member 5 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Bool = 'True`:kind! Eval (Member 5 =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (Member 7 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Bool = 'False`:kind! Eval (Member 7 =<< FromList '[ '(5,"a"), '(3,"b")])`

data NotMember :: k -> MapC k v -> Exp Bool Source #

NotMember

### Example

`>>>`

Eval (NotMember 5 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Bool = 'False`:kind! Eval (NotMember 5 =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (NotMember 7 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Bool = 'True`:kind! Eval (NotMember 7 =<< FromList '[ '(5,"a"), '(3,"b")])`

data Disjoint :: MapC k v -> MapC k v -> Exp Bool Source #

Disjoint

### Example

`>>>`

Eval (Disjoint (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(5,"B"), '(7,"C")]))) :: Bool = 'False`:kind! Eval (Disjoint (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(5,"B"), '(7,"C")])))`

`>>>`

Eval (Disjoint (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(2,"B"), '(7,"C")]))) :: Bool = 'True`:kind! Eval (Disjoint (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(2,"B"), '(7,"C")])))`

`>>>`

Eval (Disjoint (Eval Empty) (Eval Empty)) :: Bool = 'True`:kind! Eval (Disjoint (Eval Empty) (Eval Empty))`

data Elems :: MapC k v -> Exp [v] Source #

Elems

### Example

`>>>`

Eval (Elems =<< FromList '[ '(5,"a"), '(3,"b")]) :: [Symbol] = '["a", "b"]`:kind! Eval (Elems =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (Elems =<< Empty) :: [v] = '[]`:kind! Eval (Elems =<< Empty)`

data Keys :: MapC k v -> Exp [k] Source #

Keys

### Example

`>>>`

Eval (Keys =<< FromList '[ '(5,"a"), '(3,"b")]) :: [Nat] = '[5, 3]`:kind! Eval (Keys =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (Keys =<< Empty) :: [k] = '[]`:kind! Eval (Keys =<< Empty)`

data Assocs :: MapC k v -> Exp [(k, v)] Source #

Assocs

### Example

`>>>`

Eval (Assocs =<< FromList '[ '(5,"a"), '(3,"b")]) :: [(Nat, Symbol)] = '[ '(5, "a"), '(3, "b")]`:kind! Eval (Assocs =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (Assocs =<< Empty) :: [(k, v)] = '[]`:kind! Eval (Assocs =<< Empty)`

# Construction

data Empty :: Exp (MapC k v) Source #

Empty

### Example

`>>>`

(Eval Empty :: MapC Nat Symbol) :: MapC Nat Symbol = 'MapC '[]`:kind! (Eval Empty :: MapC Nat Symbol)`

`>>>`

(Eval Empty :: MapC Int String) :: MapC Int [Char] = 'MapC '[]`:kind! (Eval Empty :: MapC Int String)`

See also the other examples in this module.

data Singleton :: k -> v -> Exp (MapC k v) Source #

Singleton

### Example

`>>>`

Eval (Singleton 1 "haa") :: MapC Nat Symbol = 'MapC '[ '(1, "haa")]`:kind! Eval (Singleton 1 "haa")`

data Insert :: k -> v -> MapC k v -> Exp (MapC k v) Source #

Insert

### Example

`>>>`

Eval (Insert 3 "hih" =<< FromList '[ '(1,"haa"), '(2,"hoo")]) :: MapC Nat Symbol = 'MapC '[ '(3, "hih"), '(1, "haa"), '(2, "hoo")]`:kind! Eval (Insert 3 "hih" =<< FromList '[ '(1,"haa"), '(2,"hoo")])`

data InsertWith :: (v -> v -> Exp v) -> k -> v -> MapC k v -> Exp (MapC k v) Source #

InsertWith if old there, map if no old, add

### Example

`>>>`

Eval (InsertWith Append 5 "xxx" =<< FromList '[ '(5,"a"), '(3,"b")]) :: MapC Nat Symbol = 'MapC '[ '(5, "xxxa"), '(3, "b")]`:kind! Eval (InsertWith Append 5 "xxx" =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (InsertWith Append 7 "xxx" =<< FromList '[ '(5,"a"), '(3,"b")]) :: MapC Nat Symbol = 'MapC '[ '(5, "a"), '(3, "b"), '(7, "xxx")]`:kind! Eval (InsertWith Append 7 "xxx" =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (InsertWith Append 7 "xxx" =<< Empty) :: MapC Nat Symbol = 'MapC '[ '(7, "xxx")]`:kind! Eval (InsertWith Append 7 "xxx" =<< Empty)`

## Instances

type Eval (InsertWith f k2 v2 (MapC lst) :: MapC k1 v1 -> Type) Source # | |

Defined in Fcf.Data.MapC |

data Delete :: k -> MapC k v -> Exp (MapC k v) Source #

Delete

### Example

`>>>`

Eval (Delete 5 =<< FromList '[ '(5,"a"), '(3,"b")]) :: MapC Nat Symbol = 'MapC '[ '(3, "b")]`:kind! Eval (Delete 5 =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (Delete 7 =<< FromList '[ '(5,"a"), '(3,"b")]) :: MapC Nat Symbol = 'MapC '[ '(5, "a"), '(3, "b")]`:kind! Eval (Delete 7 =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (Delete 7 =<< Empty) :: MapC Nat v = 'MapC '[]`:kind! Eval (Delete 7 =<< Empty)`

# Combine

data Union :: MapC k v -> MapC k v -> Exp (MapC k v) Source #

Union

### Example

`>>>`

Eval (Union (Eval (FromList '[ '(5,"a"), '(3,"b")])) (Eval (FromList '[ '(5,"A"), '(7,"c")])) ) :: MapC Nat Symbol = 'MapC '[ '(7, "c"), '(5, "a"), '(3, "b")]`:kind! Eval (Union (Eval (FromList '[ '(5,"a"), '(3,"b")])) (Eval (FromList '[ '(5,"A"), '(7,"c")])) )`

data Difference :: MapC k v -> MapC k v -> Exp (MapC k v) Source #

Difference

### Example

`>>>`

Eval (Difference (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(5,"B"), '(7,"C")]))) :: MapC Nat Symbol = 'MapC '[ '(3, "a")]`:kind! Eval (Difference (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(5,"B"), '(7,"C")])))`

## Instances

type Eval (Difference mp1 mp2 :: MapC k v -> Type) Source # | |

Defined in Fcf.Data.MapC |

data Intersection :: MapC k v -> MapC k v -> Exp (MapC k v) Source #

Intersection

### Example

`>>>`

Eval (Intersection (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(5,"B"), '(7,"C")]))) :: MapC Nat Symbol = 'MapC '[ '(5, "b")]`:kind! Eval (Intersection (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(5,"B"), '(7,"C")])))`

## Instances

type Eval (Intersection mp1 mp2 :: MapC k v -> Type) Source # | |

Defined in Fcf.Data.MapC |

# Modify

data Adjust :: (v -> Exp v) -> k -> MapC k v -> Exp (MapC k v) Source #

Adjust

### Example

`>>>`

Eval (Adjust (Append "new ") 5 =<< FromList '[ '(5,"a"), '(3,"b")]) :: MapC Nat Symbol = 'MapC '[ '(5, "new a"), '(3, "b")]`:kind! Eval (Adjust (Append "new ") 5 =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (Adjust (Append "new ") 7 =<< FromList '[ '(5,"a"), '(3,"b")]) :: MapC Nat Symbol = 'MapC '[ '(5, "a"), '(3, "b")]`:kind! Eval (Adjust (Append "new ") 7 =<< FromList '[ '(5,"a"), '(3,"b")])`

`>>>`

Eval (Adjust (Append "new ") 7 =<< Empty) :: MapC Nat Symbol = 'MapC '[]`:kind! Eval (Adjust (Append "new ") 7 =<< Empty)`

data MapWithKey :: (k -> v -> Exp w) -> MapC k v -> Exp (MapC k w) Source #

## Instances

type Eval (MapWithKey f mp :: MapC k v2 -> Type) Source # | |

Defined in Fcf.Data.MapC |

data Foldr :: (v -> w -> Exp w) -> w -> MapC k v -> Exp w Source #

Foldr

Fold the values in the map using the given right-associative binary operator, such that 'foldr f z == foldr f z . elems'.

Note: the order of values in MapC is not well defined at the moment.

### Example

`>>>`

Eval (Fcf.Data.MapC.Foldr (+) 0 =<< (FromList '[ '(1,1), '(2,2)])) :: Nat = 3`:kind! Eval (Fcf.Data.MapC.Foldr (+) 0 =<< (FromList '[ '(1,1), '(2,2)]))`

data Filter :: (v -> Exp Bool) -> MapC k v -> Exp (MapC k v) Source #

Filter

### Example

`>>>`

Eval (Filter ((>=) 35) =<< FromList '[ '(5,50), '(3,30)]) :: MapC Nat Nat = 'MapC '[ '(3, 30)]`:kind! Eval (Filter ((>=) 35) =<< FromList '[ '(5,50), '(3,30)])`

data FilterWithKey :: (k -> v -> Exp Bool) -> MapC k v -> Exp (MapC k v) Source #

FilterWithKey

### Example

`>>>`

Eval (FilterWithKey (>=) =<< FromList '[ '(3,5), '(6,4)]) :: MapC Nat Nat = 'MapC '[ '(6, 4)]`:kind! Eval (FilterWithKey (>=) =<< FromList '[ '(3,5), '(6,4)])`

data Partition :: (v -> Exp Bool) -> MapC k v -> Exp (MapC k v, MapC k v) Source #

Partition

### Example

`>>>`

Eval (Partition ((>=) 35) =<< FromList '[ '(5,50), '(3,30)]) :: (MapC Nat Nat, MapC Nat Nat) = '( 'MapC '[ '(3, 30)], 'MapC '[ '(5, 50)])`:kind! Eval (Partition ((>=) 35) =<< FromList '[ '(5,50), '(3,30)])`

# List

data FromList :: [(k, v)] -> Exp (MapC k v) Source #

Use FromList to construct a MapC from type-level list.

### Example

`>>>`

Eval (FromList '[ '(1,"haa"), '(2,"hoo")]) :: MapC Nat Symbol = 'MapC '[ '(1, "haa"), '(2, "hoo")]`:kind! Eval (FromList '[ '(1,"haa"), '(2,"hoo")])`