Copyright | (c) gspia 2020- |
---|---|
License | BSD |
Maintainer | gspia |
Safe Haskell | Safe |
Language | Haskell2010 |
Fcf.Data.NatMap
NatMap provides an interface to mapping keys (Nat's) to values, which is similar to IntMap 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.
Synopsis
- data NatMap v = NatMap [(Nat, v)]
- data Null :: NatMap v -> Exp Bool
- data Size :: NatMap v -> Exp Nat
- data Lookup :: Nat -> NatMap v -> Exp (Maybe v)
- data Member :: Nat -> NatMap v -> Exp Bool
- data NotMember :: Nat -> NatMap v -> Exp Bool
- data Disjoint :: NatMap v -> NatMap v -> Exp Bool
- data Elems :: NatMap v -> Exp [v]
- data Keys :: NatMap v -> Exp [Nat]
- data Assocs :: NatMap v -> Exp [(Nat, v)]
- data Empty :: Exp (NatMap v)
- data Singleton :: Nat -> v -> Exp (NatMap v)
- data Insert :: Nat -> v -> NatMap v -> Exp (NatMap v)
- data InsertWith :: (v -> v -> Exp v) -> Nat -> v -> NatMap v -> Exp (NatMap v)
- data Delete :: Nat -> NatMap v -> Exp (NatMap v)
- data Union :: NatMap v -> NatMap v -> Exp (NatMap v)
- data Difference :: NatMap v -> NatMap v -> Exp (NatMap v)
- data Intersection :: NatMap v -> NatMap v -> Exp (NatMap v)
- data Adjust :: (v -> Exp v) -> Nat -> NatMap v -> Exp (NatMap v)
- data Map :: (v -> Exp w) -> NatMap v -> Exp (NatMap w)
- data NatMapWithKey :: (Nat -> v -> Exp w) -> NatMap v -> Exp (NatMap w)
- data Foldr :: (v -> w -> Exp w) -> w -> NatMap v -> Exp w
- data Filter :: (v -> Exp Bool) -> NatMap v -> Exp (NatMap v)
- data FilterWithKey :: (Nat -> v -> Exp Bool) -> NatMap v -> Exp (NatMap v)
- data Partition :: (v -> Exp Bool) -> NatMap v -> Exp (NatMap v, NatMap v)
- data FromList :: [(Nat, v)] -> Exp (NatMap v)
- data ToList :: NatMap v -> Exp [(Nat, v)]
NatMap type
A type corresponding to IntMap in the containers.
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.)
Instances
Query
data Null :: NatMap v -> Exp Bool Source #
Null
Example
>>>
:kind! Eval (Null =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Null =<< FromList '[ '(5,"a"), '(3,"b")]) :: Bool = 'False>>>
:kind! Eval (Null =<< Empty)
Eval (Null =<< Empty) :: Bool = 'True
data Size :: NatMap v -> Exp Nat Source #
Size
Example
>>>
:kind! Eval (Size =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Size =<< FromList '[ '(5,"a"), '(3,"b")]) :: Nat = 2
data Lookup :: Nat -> NatMap v -> Exp (Maybe v) Source #
Lookup
Example
>>>
:kind! Eval (Lookup 5 =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Lookup 5 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Maybe Symbol = 'Just "a"
>>>
:kind! Eval (Lookup 7 =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Lookup 7 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Maybe Symbol = 'Nothing
data Member :: Nat -> NatMap v -> Exp Bool Source #
Member
Example
>>>
:kind! Eval (Member 5 =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Member 5 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Bool = 'True>>>
:kind! Eval (Member 7 =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Member 7 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Bool = 'False
data NotMember :: Nat -> NatMap v -> Exp Bool Source #
NotMember
Example
>>>
:kind! Eval (NotMember 5 =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (NotMember 5 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Bool = 'False>>>
:kind! Eval (NotMember 7 =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (NotMember 7 =<< FromList '[ '(5,"a"), '(3,"b")]) :: Bool = 'True
data Disjoint :: NatMap v -> NatMap v -> Exp Bool Source #
Disjoint
Example
>>>
: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 '[ '(5,"B"), '(7,"C")]))) :: Bool = 'False
>>>
:kind! Eval (Disjoint (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(2,"B"), '(7,"C")])))
Eval (Disjoint (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(2,"B"), '(7,"C")]))) :: Bool = 'True>>>
:kind! Eval (Disjoint (Eval Empty) (Eval Empty))
Eval (Disjoint (Eval Empty) (Eval Empty)) :: Bool = 'True
data Elems :: NatMap v -> Exp [v] Source #
Elems
Example
>>>
:kind! Eval (Elems =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Elems =<< FromList '[ '(5,"a"), '(3,"b")]) :: [Symbol] = '["a", "b"]>>>
:kind! Eval (Elems =<< Empty)
Eval (Elems =<< Empty) :: [v] = '[]
data Keys :: NatMap v -> Exp [Nat] Source #
Keys
Example
>>>
:kind! Eval (Keys =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Keys =<< FromList '[ '(5,"a"), '(3,"b")]) :: [Nat] = '[5, 3]>>>
:kind! Eval (Keys =<< Empty)
Eval (Keys =<< Empty) :: [Nat] = '[]
data Assocs :: NatMap v -> Exp [(Nat, v)] Source #
Assocs
Example
>>>
:kind! Eval (Assocs =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Assocs =<< FromList '[ '(5,"a"), '(3,"b")]) :: [(Nat, Symbol)] = '[ '(5, "a"), '(3, "b")]>>>
:kind! Eval (Assocs =<< Empty)
Eval (Assocs =<< Empty) :: [(Nat, v)] = '[]
Construction
data Empty :: Exp (NatMap v) Source #
Empty
Example
>>>
:kind! (Eval Empty :: NatMap Symbol)
(Eval Empty :: NatMap Symbol) :: NatMap Symbol = 'NatMap '[]
>>>
:kind! (Eval Empty :: NatMap String)
(Eval Empty :: NatMap String) :: NatMap [Char] = 'NatMap '[]
See also the other examples in this module.
data Singleton :: Nat -> v -> Exp (NatMap v) Source #
Singleton
Example
>>>
:kind! Eval (Singleton 1 "haa")
Eval (Singleton 1 "haa") :: NatMap Symbol = 'NatMap '[ '(1, "haa")]
data Insert :: Nat -> v -> NatMap v -> Exp (NatMap v) Source #
Insert
Example
>>>
:kind! Eval (Insert 3 "hih" =<< FromList '[ '(1,"haa"), '(2,"hoo")])
Eval (Insert 3 "hih" =<< FromList '[ '(1,"haa"), '(2,"hoo")]) :: NatMap Symbol = 'NatMap '[ '(3, "hih"), '(1, "haa"), '(2, "hoo")]
data InsertWith :: (v -> v -> Exp v) -> Nat -> v -> NatMap v -> Exp (NatMap v) Source #
InsertWith
if old there, map
if no old, add
Example
>>>
:kind! Eval (InsertWith Append 5 "xxx" =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (InsertWith Append 5 "xxx" =<< FromList '[ '(5,"a"), '(3,"b")]) :: NatMap Symbol = 'NatMap '[ '(5, "xxxa"), '(3, "b")]
>>>
:kind! Eval (InsertWith Append 7 "xxx" =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (InsertWith Append 7 "xxx" =<< FromList '[ '(5,"a"), '(3,"b")]) :: NatMap Symbol = 'NatMap '[ '(5, "a"), '(3, "b"), '(7, "xxx")]
>>>
:kind! Eval (InsertWith Append 7 "xxx" =<< Empty)
Eval (InsertWith Append 7 "xxx" =<< Empty) :: NatMap Symbol = 'NatMap '[ '(7, "xxx")]
Instances
type Eval (InsertWith f k v2 (NatMap lst) :: NatMap v1 -> Type) Source # | |
Defined in Fcf.Data.NatMap |
data Delete :: Nat -> NatMap v -> Exp (NatMap v) Source #
Delete
Example
>>>
:kind! Eval (Delete 5 =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Delete 5 =<< FromList '[ '(5,"a"), '(3,"b")]) :: NatMap Symbol = 'NatMap '[ '(3, "b")]
>>>
:kind! Eval (Delete 7 =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Delete 7 =<< FromList '[ '(5,"a"), '(3,"b")]) :: NatMap Symbol = 'NatMap '[ '(5, "a"), '(3, "b")]
>>>
:kind! Eval (Delete 7 =<< Empty)
Eval (Delete 7 =<< Empty) :: NatMap v = 'NatMap '[]
Combine
data Union :: NatMap v -> NatMap v -> Exp (NatMap v) Source #
Union
Example
>>>
:kind! Eval (Union (Eval (FromList '[ '(5,"a"), '(3,"b")])) (Eval (FromList '[ '(5,"A"), '(7,"c")])) )
Eval (Union (Eval (FromList '[ '(5,"a"), '(3,"b")])) (Eval (FromList '[ '(5,"A"), '(7,"c")])) ) :: NatMap Symbol = 'NatMap '[ '(7, "c"), '(5, "a"), '(3, "b")]
data Difference :: NatMap v -> NatMap v -> Exp (NatMap v) Source #
Difference
Example
>>>
:kind! Eval (Difference (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(5,"B"), '(7,"C")])))
Eval (Difference (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(5,"B"), '(7,"C")]))) :: NatMap Symbol = 'NatMap '[ '(3, "a")]
Instances
type Eval (Difference mp1 mp2 :: NatMap v -> Type) Source # | |
Defined in Fcf.Data.NatMap |
data Intersection :: NatMap v -> NatMap v -> Exp (NatMap v) Source #
Intersection
Example
>>>
:kind! Eval (Intersection (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(5,"B"), '(7,"C")])))
Eval (Intersection (Eval (FromList '[ '(3,"a"), '(5,"b")])) (Eval (FromList '[ '(5,"B"), '(7,"C")]))) :: NatMap Symbol = 'NatMap '[ '(5, "b")]
Instances
type Eval (Intersection mp1 mp2 :: NatMap v -> Type) Source # | |
Defined in Fcf.Data.NatMap |
Modify
data Adjust :: (v -> Exp v) -> Nat -> NatMap v -> Exp (NatMap v) Source #
Adjust
Example
>>>
:kind! Eval (Adjust (Append "new ") 5 =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Adjust (Append "new ") 5 =<< FromList '[ '(5,"a"), '(3,"b")]) :: NatMap Symbol = 'NatMap '[ '(5, "new a"), '(3, "b")]
>>>
:kind! Eval (Adjust (Append "new ") 7 =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Adjust (Append "new ") 7 =<< FromList '[ '(5,"a"), '(3,"b")]) :: NatMap Symbol = 'NatMap '[ '(5, "a"), '(3, "b")]
>>>
:kind! Eval (Adjust (Append "new ") 7 =<< Empty)
Eval (Adjust (Append "new ") 7 =<< Empty) :: NatMap Symbol = 'NatMap '[]
data Map :: (v -> Exp w) -> NatMap v -> Exp (NatMap w) Source #
Map
Example
>>>
:kind! Eval (Fcf.Data.NatMap.Map (Append "x") =<< FromList '[ '(5,"a"), '(3,"b")])
Eval (Fcf.Data.NatMap.Map (Append "x") =<< FromList '[ '(5,"a"), '(3,"b")]) :: NatMap Symbol = 'NatMap '[ '(5, "xa"), '(3, "xb")]
data NatMapWithKey :: (Nat -> v -> Exp w) -> NatMap v -> Exp (NatMap w) Source #
NatMapWithKey
Example
Instances
type Eval (NatMapWithKey f mp :: NatMap v2 -> Type) Source # | |
Defined in Fcf.Data.NatMap |
data Foldr :: (v -> w -> Exp w) -> w -> NatMap 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 NatMap is not well defined at the moment.
Example
>>>
:kind! Eval (Fcf.Data.NatMap.Foldr (+) 0 =<< (FromList '[ '(1,1), '(2,2)]))
Eval (Fcf.Data.NatMap.Foldr (+) 0 =<< (FromList '[ '(1,1), '(2,2)])) :: Nat = 3
data Filter :: (v -> Exp Bool) -> NatMap v -> Exp (NatMap v) Source #
Filter
Example
>>>
:kind! Eval (Filter ((>=) 35) =<< FromList '[ '(5,50), '(3,30)])
Eval (Filter ((>=) 35) =<< FromList '[ '(5,50), '(3,30)]) :: NatMap Nat = 'NatMap '[ '(3, 30)]
data FilterWithKey :: (Nat -> v -> Exp Bool) -> NatMap v -> Exp (NatMap v) Source #
FilterWithKey
Example
>>>
:kind! Eval (FilterWithKey (>=) =<< FromList '[ '(3,5), '(6,4)])
Eval (FilterWithKey (>=) =<< FromList '[ '(3,5), '(6,4)]) :: NatMap Nat = 'NatMap '[ '(6, 4)]
data Partition :: (v -> Exp Bool) -> NatMap v -> Exp (NatMap v, NatMap v) Source #
Partition
Example
>>>
:kind! Eval (Partition ((>=) 35) =<< FromList '[ '(5,50), '(3,30)])
Eval (Partition ((>=) 35) =<< FromList '[ '(5,50), '(3,30)]) :: (NatMap Nat, NatMap Nat) = '( 'NatMap '[ '(3, 30)], 'NatMap '[ '(5, 50)])
List
data FromList :: [(Nat, v)] -> Exp (NatMap v) Source #
Use FromList to construct a NatMap from type-level list.
Example
>>>
:kind! Eval (FromList '[ '(1,"haa"), '(2,"hoo")])
Eval (FromList '[ '(1,"haa"), '(2,"hoo")]) :: NatMap Symbol = 'NatMap '[ '(1, "haa"), '(2, "hoo")]