{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Multimap.Table.Internal (
Table (..)
, Size
, empty
, singleton
, fromRowMap
, fromColumnMap
, transpose
, fromList
, insert
, delete
, deleteRow
, deleteColumn
, adjust
, adjustWithKeys
, update
, updateWithKeys
, alter
, alterWithKeys
, lookup
, (!?)
, (!)
, hasCell
, hasRow
, hasColumn
, null
, notNull
, size
, union
, unionWith
, unionWithKeys
, unions
, unionsWith
, unionsWithKeys
, difference
, map
, mapWithKeys
, traverseWithKeys
, traverseMaybeWithKeys
, foldr
, foldl
, foldrWithKeys
, foldlWithKeys
, foldMapWithKeys
, foldr'
, foldl'
, foldrWithKeys'
, foldlWithKeys'
, row
, column
, rowMap
, columnMap
, rowKeys
, columnKeys
, rowKeysSet
, columnKeysSet
, toList
, toRowAscList
, toColumnAscList
, toRowDescList
, toColumnDescList
, filter
, filterRow
, filterColumn
, filterWithKeys
, mapMaybe
, mapMaybeWithKeys
, mapEither
, mapEitherWithKeys
) where
import Control.Arrow ((&&&))
import Data.Data (Data)
import qualified Data.Foldable as Foldable
import Data.Map (Map)
import qualified Data.Map as Map
import qualified Data.Maybe as Maybe
import Data.Set (Set)
import Prelude hiding (filter, foldl, foldr, lookup, map, null)
infixl 9 !,!?
type Size = Int
newtype Table r c a = Table (Map r (Map c a), Map c (Map r a), Size)
deriving (Table r c a -> Table r c a -> Bool
(Table r c a -> Table r c a -> Bool)
-> (Table r c a -> Table r c a -> Bool) -> Eq (Table r c a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall r c a.
(Eq r, Eq c, Eq a) =>
Table r c a -> Table r c a -> Bool
/= :: Table r c a -> Table r c a -> Bool
$c/= :: forall r c a.
(Eq r, Eq c, Eq a) =>
Table r c a -> Table r c a -> Bool
== :: Table r c a -> Table r c a -> Bool
$c== :: forall r c a.
(Eq r, Eq c, Eq a) =>
Table r c a -> Table r c a -> Bool
Eq, Eq (Table r c a)
Eq (Table r c a)
-> (Table r c a -> Table r c a -> Ordering)
-> (Table r c a -> Table r c a -> Bool)
-> (Table r c a -> Table r c a -> Bool)
-> (Table r c a -> Table r c a -> Bool)
-> (Table r c a -> Table r c a -> Bool)
-> (Table r c a -> Table r c a -> Table r c a)
-> (Table r c a -> Table r c a -> Table r c a)
-> Ord (Table r c a)
Table r c a -> Table r c a -> Bool
Table r c a -> Table r c a -> Ordering
Table r c a -> Table r c a -> Table r c a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall r c a. (Ord r, Ord c, Ord a) => Eq (Table r c a)
forall r c a.
(Ord r, Ord c, Ord a) =>
Table r c a -> Table r c a -> Bool
forall r c a.
(Ord r, Ord c, Ord a) =>
Table r c a -> Table r c a -> Ordering
forall r c a.
(Ord r, Ord c, Ord a) =>
Table r c a -> Table r c a -> Table r c a
min :: Table r c a -> Table r c a -> Table r c a
$cmin :: forall r c a.
(Ord r, Ord c, Ord a) =>
Table r c a -> Table r c a -> Table r c a
max :: Table r c a -> Table r c a -> Table r c a
$cmax :: forall r c a.
(Ord r, Ord c, Ord a) =>
Table r c a -> Table r c a -> Table r c a
>= :: Table r c a -> Table r c a -> Bool
$c>= :: forall r c a.
(Ord r, Ord c, Ord a) =>
Table r c a -> Table r c a -> Bool
> :: Table r c a -> Table r c a -> Bool
$c> :: forall r c a.
(Ord r, Ord c, Ord a) =>
Table r c a -> Table r c a -> Bool
<= :: Table r c a -> Table r c a -> Bool
$c<= :: forall r c a.
(Ord r, Ord c, Ord a) =>
Table r c a -> Table r c a -> Bool
< :: Table r c a -> Table r c a -> Bool
$c< :: forall r c a.
(Ord r, Ord c, Ord a) =>
Table r c a -> Table r c a -> Bool
compare :: Table r c a -> Table r c a -> Ordering
$ccompare :: forall r c a.
(Ord r, Ord c, Ord a) =>
Table r c a -> Table r c a -> Ordering
$cp1Ord :: forall r c a. (Ord r, Ord c, Ord a) => Eq (Table r c a)
Ord, Typeable (Table r c a)
DataType
Constr
Typeable (Table r c a)
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table r c a -> c (Table r c a))
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Table r c a))
-> (Table r c a -> Constr)
-> (Table r c a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Table r c a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Table r c a)))
-> ((forall b. Data b => b -> b) -> Table r c a -> Table r c a)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Table r c a -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Table r c a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Table r c a -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> Table r c a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a))
-> Data (Table r c a)
Table r c a -> DataType
Table r c a -> Constr
(forall b. Data b => b -> b) -> Table r c a -> Table r c a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table r c a -> c (Table r c a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Table r c a)
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Table r c a -> u
forall u. (forall d. Data d => d -> u) -> Table r c a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Table r c a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Table r c a -> r
forall r c a.
(Data r, Data c, Data a, Ord c, Ord r) =>
Typeable (Table r c a)
forall r c a.
(Data r, Data c, Data a, Ord c, Ord r) =>
Table r c a -> DataType
forall r c a.
(Data r, Data c, Data a, Ord c, Ord r) =>
Table r c a -> Constr
forall r c a.
(Data r, Data c, Data a, Ord c, Ord r) =>
(forall b. Data b => b -> b) -> Table r c a -> Table r c a
forall r c a u.
(Data r, Data c, Data a, Ord c, Ord r) =>
Int -> (forall d. Data d => d -> u) -> Table r c a -> u
forall r c a u.
(Data r, Data c, Data a, Ord c, Ord r) =>
(forall d. Data d => d -> u) -> Table r c a -> [u]
forall r c a r r'.
(Data r, Data c, Data a, Ord c, Ord r) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Table r c a -> r
forall r c a r r'.
(Data r, Data c, Data a, Ord c, Ord r) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Table r c a -> r
forall r c a (m :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r, Monad m) =>
(forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a)
forall r c a (m :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a)
forall r c a (c :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Table r c a)
forall r c a (c :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table r c a -> c (Table r c a)
forall r c a (t :: * -> *) (c :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Table r c a))
forall r c a (t :: * -> * -> *) (c :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Table r c a))
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Table r c a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table r c a -> c (Table r c a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Table r c a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Table r c a))
$cTable :: Constr
$tTable :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a)
$cgmapMo :: forall r c a (m :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a)
gmapMp :: (forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a)
$cgmapMp :: forall r c a (m :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a)
gmapM :: (forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a)
$cgmapM :: forall r c a (m :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r, Monad m) =>
(forall d. Data d => d -> m d) -> Table r c a -> m (Table r c a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> Table r c a -> u
$cgmapQi :: forall r c a u.
(Data r, Data c, Data a, Ord c, Ord r) =>
Int -> (forall d. Data d => d -> u) -> Table r c a -> u
gmapQ :: (forall d. Data d => d -> u) -> Table r c a -> [u]
$cgmapQ :: forall r c a u.
(Data r, Data c, Data a, Ord c, Ord r) =>
(forall d. Data d => d -> u) -> Table r c a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Table r c a -> r
$cgmapQr :: forall r c a r r'.
(Data r, Data c, Data a, Ord c, Ord r) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Table r c a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Table r c a -> r
$cgmapQl :: forall r c a r r'.
(Data r, Data c, Data a, Ord c, Ord r) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Table r c a -> r
gmapT :: (forall b. Data b => b -> b) -> Table r c a -> Table r c a
$cgmapT :: forall r c a.
(Data r, Data c, Data a, Ord c, Ord r) =>
(forall b. Data b => b -> b) -> Table r c a -> Table r c a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Table r c a))
$cdataCast2 :: forall r c a (t :: * -> * -> *) (c :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Table r c a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Table r c a))
$cdataCast1 :: forall r c a (t :: * -> *) (c :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Table r c a))
dataTypeOf :: Table r c a -> DataType
$cdataTypeOf :: forall r c a.
(Data r, Data c, Data a, Ord c, Ord r) =>
Table r c a -> DataType
toConstr :: Table r c a -> Constr
$ctoConstr :: forall r c a.
(Data r, Data c, Data a, Ord c, Ord r) =>
Table r c a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Table r c a)
$cgunfold :: forall r c a (c :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Table r c a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table r c a -> c (Table r c a)
$cgfoldl :: forall r c a (c :: * -> *).
(Data r, Data c, Data a, Ord c, Ord r) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table r c a -> c (Table r c a)
$cp1Data :: forall r c a.
(Data r, Data c, Data a, Ord c, Ord r) =>
Typeable (Table r c a)
Data)
instance (Show r, Show c, Show a) => Show (Table r c a) where
showsPrec :: Int -> Table r c a -> ShowS
showsPrec Int
d Table r c a
m = Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
String -> ShowS
showString String
"fromList " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(r, c, a)] -> ShowS
forall a. Show a => a -> ShowS
shows (Table r c a -> [(r, c, a)]
forall r c a. Table r c a -> [(r, c, a)]
toList Table r c a
m)
instance (Ord r, Ord c, Read r, Read c, Read a) => Read (Table r c a) where
readsPrec :: Int -> ReadS (Table r c a)
readsPrec Int
p = Bool -> ReadS (Table r c a) -> ReadS (Table r c a)
forall a. Bool -> ReadS a -> ReadS a
readParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ReadS (Table r c a) -> ReadS (Table r c a))
-> ReadS (Table r c a) -> ReadS (Table r c a)
forall a b. (a -> b) -> a -> b
$ \ String
r -> do
(String
"fromList",String
s) <- ReadS String
lex String
r
([(r, c, a)]
xs,String
t) <- ReadS [(r, c, a)]
forall a. Read a => ReadS a
reads String
s
(Table r c a, String) -> [(Table r c a, String)]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([(r, c, a)] -> Table r c a
forall r c a. (Ord r, Ord c) => [(r, c, a)] -> Table r c a
fromList [(r, c, a)]
xs,String
t)
instance Functor (Table r c) where
fmap :: (a -> b) -> Table r c a -> Table r c b
fmap = (a -> b) -> Table r c a -> Table r c b
forall a b r c. (a -> b) -> Table r c a -> Table r c b
map
instance Foldable.Foldable (Table r c) where
foldMap :: (a -> m) -> Table r c a -> m
foldMap = (r -> c -> a -> m) -> Table r c a -> m
forall m r c a. Monoid m => (r -> c -> a -> m) -> Table r c a -> m
foldMapWithKeys ((r -> c -> a -> m) -> Table r c a -> m)
-> ((a -> m) -> r -> c -> a -> m) -> (a -> m) -> Table r c a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> m) -> r -> c -> a -> m
forall a b. a -> b -> a
const ((c -> a -> m) -> r -> c -> a -> m)
-> ((a -> m) -> c -> a -> m) -> (a -> m) -> r -> c -> a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m) -> c -> a -> m
forall a b. a -> b -> a
const
{-# INLINE foldMap #-}
instance (Ord r, Ord c) => Traversable (Table r c) where
traverse :: (a -> f b) -> Table r c a -> f (Table r c b)
traverse = (r -> c -> a -> f b) -> Table r c a -> f (Table r c b)
forall (t :: * -> *) r c a b.
(Applicative t, Ord r, Ord c) =>
(r -> c -> a -> t b) -> Table r c a -> t (Table r c b)
traverseWithKeys ((r -> c -> a -> f b) -> Table r c a -> f (Table r c b))
-> ((a -> f b) -> r -> c -> a -> f b)
-> (a -> f b)
-> Table r c a
-> f (Table r c b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> f b) -> r -> c -> a -> f b
forall a b. a -> b -> a
const ((c -> a -> f b) -> r -> c -> a -> f b)
-> ((a -> f b) -> c -> a -> f b)
-> (a -> f b)
-> r
-> c
-> a
-> f b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> c -> a -> f b
forall a b. a -> b -> a
const
{-# INLINE traverse #-}
instance (Ord r, Ord c) => Semigroup (Table r c a) where
<> :: Table r c a -> Table r c a -> Table r c a
(<>) = Table r c a -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
Table r c a -> Table r c a -> Table r c a
union
instance (Ord r, Ord c) => Monoid (Table r c a) where
mempty :: Table r c a
mempty = Table r c a
forall r c a. Table r c a
empty
mappend :: Table r c a -> Table r c a -> Table r c a
mappend = Table r c a -> Table r c a -> Table r c a
forall a. Semigroup a => a -> a -> a
(<>)
empty :: Table r c a
empty :: Table r c a
empty = (Map r (Map c a), Map c (Map r a), Int) -> Table r c a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map r (Map c a)
forall k a. Map k a
Map.empty, Map c (Map r a)
forall k a. Map k a
Map.empty, Int
0)
singleton :: r -> c -> a -> Table r c a
singleton :: r -> c -> a -> Table r c a
singleton r
r c
c a
a = (Map r (Map c a), Map c (Map r a), Int) -> Table r c a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (r -> Map c a -> Map r (Map c a)
forall k a. k -> a -> Map k a
Map.singleton r
r (c -> a -> Map c a
forall k a. k -> a -> Map k a
Map.singleton c
c a
a), c -> Map r a -> Map c (Map r a)
forall k a. k -> a -> Map k a
Map.singleton c
c (r -> a -> Map r a
forall k a. k -> a -> Map k a
Map.singleton r
r a
a), Int
1)
fromList :: (Ord r, Ord c) => [(r, c, a)] -> Table r c a
fromList :: [(r, c, a)] -> Table r c a
fromList = ((r, c, a) -> Table r c a -> Table r c a)
-> Table r c a -> [(r, c, a)] -> Table r c a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr ((r -> c -> a -> Table r c a -> Table r c a)
-> (r, c, a) -> Table r c a -> Table r c a
forall a b c d. (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 r -> c -> a -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
r -> c -> a -> Table r c a -> Table r c a
insert) Table r c a
forall r c a. Table r c a
empty
fromRowMap :: (Ord r, Ord c) => Map r (Map c a) -> Table r c a
fromRowMap :: Map r (Map c a) -> Table r c a
fromRowMap Map r (Map c a)
m = (Map r (Map c a), Map c (Map r a), Int) -> Table r c a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map r (Map c a)
m', Map r (Map c a) -> Map c (Map r a)
forall r c a. (Ord r, Ord c) => Map r (Map c a) -> Map c (Map r a)
transpose' Map r (Map c a)
m', Map r (Map c a) -> Int
forall k1 k2 a. Map k1 (Map k2 a) -> Int
size' Map r (Map c a)
m')
where m' :: Map r (Map c a)
m' = Map r (Map c a) -> Map r (Map c a)
forall k1 k2 a. Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty Map r (Map c a)
m
fromColumnMap :: (Ord r, Ord c) => Map c (Map r a) -> Table r c a
fromColumnMap :: Map c (Map r a) -> Table r c a
fromColumnMap Map c (Map r a)
m = (Map r (Map c a), Map c (Map r a), Int) -> Table r c a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map c (Map r a) -> Map r (Map c a)
forall r c a. (Ord r, Ord c) => Map r (Map c a) -> Map c (Map r a)
transpose' Map c (Map r a)
m', Map c (Map r a)
m', Map c (Map r a) -> Int
forall k1 k2 a. Map k1 (Map k2 a) -> Int
size' Map c (Map r a)
m')
where m' :: Map c (Map r a)
m' = Map c (Map r a) -> Map c (Map r a)
forall k1 k2 a. Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty Map c (Map r a)
m
transpose :: Table r c a -> Table c r a
transpose :: Table r c a -> Table c r a
transpose (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
sz)) = (Map c (Map r a), Map r (Map c a), Int) -> Table c r a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map c (Map r a)
cm, Map r (Map c a)
rm, Int
sz)
insert :: (Ord r, Ord c) => r -> c -> a -> Table r c a -> Table r c a
insert :: r -> c -> a -> Table r c a -> Table r c a
insert r
r c
c a
a (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
_)) = r -> c -> Map r (Map c a) -> Map c (Map r a) -> Table r c a
forall r c a.
(Ord r, Ord c) =>
r -> c -> Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps' r
r c
c Map r (Map c a)
rm' Map c (Map r a)
cm'
where
rm' :: Map r (Map c a)
rm' = (Maybe (Map c a) -> Maybe (Map c a))
-> r -> Map r (Map c a) -> Map r (Map c a)
forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
Map.alter Maybe (Map c a) -> Maybe (Map c a)
f r
r Map r (Map c a)
rm
cm' :: Map c (Map r a)
cm' = (Maybe (Map r a) -> Maybe (Map r a))
-> c -> Map c (Map r a) -> Map c (Map r a)
forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
Map.alter Maybe (Map r a) -> Maybe (Map r a)
g c
c Map c (Map r a)
cm
f :: Maybe (Map c a) -> Maybe (Map c a)
f = Map c a -> Maybe (Map c a)
forall a. a -> Maybe a
Just (Map c a -> Maybe (Map c a))
-> (Maybe (Map c a) -> Map c a)
-> Maybe (Map c a)
-> Maybe (Map c a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map c a -> (Map c a -> Map c a) -> Maybe (Map c a) -> Map c a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (c -> a -> Map c a
forall k a. k -> a -> Map k a
Map.singleton c
c a
a) (c -> a -> Map c a -> Map c a
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert c
c a
a)
g :: Maybe (Map r a) -> Maybe (Map r a)
g = Map r a -> Maybe (Map r a)
forall a. a -> Maybe a
Just (Map r a -> Maybe (Map r a))
-> (Maybe (Map r a) -> Map r a)
-> Maybe (Map r a)
-> Maybe (Map r a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map r a -> (Map r a -> Map r a) -> Maybe (Map r a) -> Map r a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (r -> a -> Map r a
forall k a. k -> a -> Map k a
Map.singleton r
r a
a) (r -> a -> Map r a -> Map r a
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert r
r a
a)
delete :: (Ord r, Ord c) => r -> c -> Table r c a -> Table r c a
delete :: r -> c -> Table r c a -> Table r c a
delete r
r c
c (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
_)) = r -> c -> Map r (Map c a) -> Map c (Map r a) -> Table r c a
forall r c a.
(Ord r, Ord c) =>
r -> c -> Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps' r
r c
c Map r (Map c a)
rm' Map c (Map r a)
cm'
where
rm' :: Map r (Map c a)
rm' = (Map c a -> Map c a) -> r -> Map r (Map c a) -> Map r (Map c a)
forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
Map.adjust (c -> Map c a -> Map c a
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete c
c) r
r Map r (Map c a)
rm
cm' :: Map c (Map r a)
cm' = (Map r a -> Map r a) -> c -> Map c (Map r a) -> Map c (Map r a)
forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
Map.adjust (r -> Map r a -> Map r a
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete r
r) c
c Map c (Map r a)
cm
deleteRow :: Ord r => r -> Table r c a -> Table r c a
deleteRow :: r -> Table r c a -> Table r c a
deleteRow r
r (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
_)) = (Map r (Map c a), Map c (Map r a), Int) -> Table r c a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map r (Map c a)
rm', Map c (Map r a)
cm', Map r (Map c a) -> Int
forall k1 k2 a. Map k1 (Map k2 a) -> Int
size' Map r (Map c a)
rm')
where
rm' :: Map r (Map c a)
rm' = r -> Map r (Map c a) -> Map r (Map c a)
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete r
r Map r (Map c a)
rm
cm' :: Map c (Map r a)
cm' = Map c (Map r a) -> Map c (Map r a)
forall k1 k2 a. Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty (Map c (Map r a) -> Map c (Map r a))
-> Map c (Map r a) -> Map c (Map r a)
forall a b. (a -> b) -> a -> b
$ (Map r a -> Map r a) -> Map c (Map r a) -> Map c (Map r a)
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (r -> Map r a -> Map r a
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete r
r) Map c (Map r a)
cm
deleteColumn :: Ord c => c -> Table r c a -> Table r c a
deleteColumn :: c -> Table r c a -> Table r c a
deleteColumn c
c (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
_)) = (Map r (Map c a), Map c (Map r a), Int) -> Table r c a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map r (Map c a)
rm', Map c (Map r a)
cm', Map c (Map r a) -> Int
forall k1 k2 a. Map k1 (Map k2 a) -> Int
size' Map c (Map r a)
cm')
where
rm' :: Map r (Map c a)
rm' = Map r (Map c a) -> Map r (Map c a)
forall k1 k2 a. Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty (Map r (Map c a) -> Map r (Map c a))
-> Map r (Map c a) -> Map r (Map c a)
forall a b. (a -> b) -> a -> b
$ (Map c a -> Map c a) -> Map r (Map c a) -> Map r (Map c a)
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (c -> Map c a -> Map c a
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete c
c) Map r (Map c a)
rm
cm' :: Map c (Map r a)
cm' = c -> Map c (Map r a) -> Map c (Map r a)
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete c
c Map c (Map r a)
cm
adjust :: (Ord r, Ord c) => (a -> a) -> r -> c -> Table r c a -> Table r c a
adjust :: (a -> a) -> r -> c -> Table r c a -> Table r c a
adjust = (r -> c -> a -> a) -> r -> c -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
(r -> c -> a -> a) -> r -> c -> Table r c a -> Table r c a
adjustWithKeys ((r -> c -> a -> a) -> r -> c -> Table r c a -> Table r c a)
-> ((a -> a) -> r -> c -> a -> a)
-> (a -> a)
-> r
-> c
-> Table r c a
-> Table r c a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> a) -> r -> c -> a -> a
forall a b. a -> b -> a
const ((c -> a -> a) -> r -> c -> a -> a)
-> ((a -> a) -> c -> a -> a) -> (a -> a) -> r -> c -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a) -> c -> a -> a
forall a b. a -> b -> a
const
adjustWithKeys
:: (Ord r, Ord c)
=> (r -> c -> a -> a) -> r -> c -> Table r c a -> Table r c a
adjustWithKeys :: (r -> c -> a -> a) -> r -> c -> Table r c a -> Table r c a
adjustWithKeys r -> c -> a -> a
f = (r -> c -> a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
(r -> c -> a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
updateWithKeys (\r
r c
c a
a -> a -> Maybe a
forall a. a -> Maybe a
Just (r -> c -> a -> a
f r
r c
c a
a))
update :: (Ord r, Ord c) => (a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
update :: (a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
update = (r -> c -> a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
(r -> c -> a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
updateWithKeys ((r -> c -> a -> Maybe a) -> r -> c -> Table r c a -> Table r c a)
-> ((a -> Maybe a) -> r -> c -> a -> Maybe a)
-> (a -> Maybe a)
-> r
-> c
-> Table r c a
-> Table r c a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> Maybe a) -> r -> c -> a -> Maybe a
forall a b. a -> b -> a
const ((c -> a -> Maybe a) -> r -> c -> a -> Maybe a)
-> ((a -> Maybe a) -> c -> a -> Maybe a)
-> (a -> Maybe a)
-> r
-> c
-> a
-> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Maybe a) -> c -> a -> Maybe a
forall a b. a -> b -> a
const
updateWithKeys
:: (Ord r, Ord c)
=> (r -> c -> a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
updateWithKeys :: (r -> c -> a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
updateWithKeys r -> c -> a -> Maybe a
f = (r -> c -> Maybe a -> Maybe a)
-> r -> c -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
(r -> c -> Maybe a -> Maybe a)
-> r -> c -> Table r c a -> Table r c a
alterWithKeys (\r
r c
c -> (Maybe a -> (a -> Maybe a) -> Maybe a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= r -> c -> a -> Maybe a
f r
r c
c))
alter :: (Ord r, Ord c) => (Maybe a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
alter :: (Maybe a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
alter = (r -> c -> Maybe a -> Maybe a)
-> r -> c -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
(r -> c -> Maybe a -> Maybe a)
-> r -> c -> Table r c a -> Table r c a
alterWithKeys ((r -> c -> Maybe a -> Maybe a)
-> r -> c -> Table r c a -> Table r c a)
-> ((Maybe a -> Maybe a) -> r -> c -> Maybe a -> Maybe a)
-> (Maybe a -> Maybe a)
-> r
-> c
-> Table r c a
-> Table r c a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> Maybe a -> Maybe a) -> r -> c -> Maybe a -> Maybe a
forall a b. a -> b -> a
const ((c -> Maybe a -> Maybe a) -> r -> c -> Maybe a -> Maybe a)
-> ((Maybe a -> Maybe a) -> c -> Maybe a -> Maybe a)
-> (Maybe a -> Maybe a)
-> r
-> c
-> Maybe a
-> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe a -> Maybe a) -> c -> Maybe a -> Maybe a
forall a b. a -> b -> a
const
alterWithKeys
:: (Ord r, Ord c)
=> (r -> c -> Maybe a -> Maybe a) -> r -> c -> Table r c a -> Table r c a
alterWithKeys :: (r -> c -> Maybe a -> Maybe a)
-> r -> c -> Table r c a -> Table r c a
alterWithKeys r -> c -> Maybe a -> Maybe a
f r
r c
c tbl :: Table r c a
tbl@(Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
_))
| Just a
a <- r -> c -> Maybe a -> Maybe a
f r
r c
c (r -> c -> Table r c a -> Maybe a
forall r c a. (Ord r, Ord c) => r -> c -> Table r c a -> Maybe a
lookup r
r c
c Table r c a
tbl) =
let rm' :: Map r (Map c a)
rm' = (Maybe (Map c a) -> Maybe (Map c a))
-> r -> Map r (Map c a) -> Map r (Map c a)
forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
Map.alter (Map c a -> Maybe (Map c a)
forall a. a -> Maybe a
Just (Map c a -> Maybe (Map c a))
-> (Maybe (Map c a) -> Map c a)
-> Maybe (Map c a)
-> Maybe (Map c a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map c a -> (Map c a -> Map c a) -> Maybe (Map c a) -> Map c a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (c -> a -> Map c a
forall k a. k -> a -> Map k a
Map.singleton c
c a
a) (c -> a -> Map c a -> Map c a
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert c
c a
a)) r
r Map r (Map c a)
rm
cm' :: Map c (Map r a)
cm' = (Maybe (Map r a) -> Maybe (Map r a))
-> c -> Map c (Map r a) -> Map c (Map r a)
forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
Map.alter (Map r a -> Maybe (Map r a)
forall a. a -> Maybe a
Just (Map r a -> Maybe (Map r a))
-> (Maybe (Map r a) -> Map r a)
-> Maybe (Map r a)
-> Maybe (Map r a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map r a -> (Map r a -> Map r a) -> Maybe (Map r a) -> Map r a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (r -> a -> Map r a
forall k a. k -> a -> Map k a
Map.singleton r
r a
a) (r -> a -> Map r a -> Map r a
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert r
r a
a)) c
c Map c (Map r a)
cm
in r -> c -> Map r (Map c a) -> Map c (Map r a) -> Table r c a
forall r c a.
(Ord r, Ord c) =>
r -> c -> Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps' r
r c
c Map r (Map c a)
rm' Map c (Map r a)
cm'
| Bool
otherwise = r -> c -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
r -> c -> Table r c a -> Table r c a
delete r
r c
c Table r c a
tbl
lookup :: (Ord r, Ord c) => r -> c -> Table r c a -> Maybe a
lookup :: r -> c -> Table r c a -> Maybe a
lookup r
r c
c (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = r -> Map r (Map c a) -> Maybe (Map c a)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup r
r Map r (Map c a)
rm Maybe (Map c a) -> (Map c a -> Maybe a) -> Maybe a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= c -> Map c a -> Maybe a
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup c
c
(!?) :: (Ord r, Ord c) => Table r c a -> (r, c) -> Maybe a
!? :: Table r c a -> (r, c) -> Maybe a
(!?) = ((r, c) -> Table r c a -> Maybe a)
-> Table r c a -> (r, c) -> Maybe a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((r -> c -> Table r c a -> Maybe a)
-> (r, c) -> Table r c a -> Maybe a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry r -> c -> Table r c a -> Maybe a
forall r c a. (Ord r, Ord c) => r -> c -> Table r c a -> Maybe a
lookup)
(!) :: (Ord r, Ord c) => Table r c a -> (r, c) -> a
(!) Table r c a
tbl (r, c)
keys =
a -> Maybe a -> a
forall a. a -> Maybe a -> a
Maybe.fromMaybe (String -> a
forall a. HasCallStack => String -> a
error String
"Table.!: cell does not exist") (Table r c a
tbl Table r c a -> (r, c) -> Maybe a
forall r c a. (Ord r, Ord c) => Table r c a -> (r, c) -> Maybe a
!? (r, c)
keys)
hasCell :: (Ord r, Ord c) => Table r c a -> (r, c) -> Bool
hasCell :: Table r c a -> (r, c) -> Bool
hasCell (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) (r
r, c
c) =
Bool -> (Map c a -> Bool) -> Maybe (Map c a) -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (c -> Map c a -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.member c
c) (r -> Map r (Map c a) -> Maybe (Map c a)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup r
r Map r (Map c a)
rm)
hasRow :: Ord r => Table r c a -> r -> Bool
hasRow :: Table r c a -> r -> Bool
hasRow (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) r
r = r -> Map r (Map c a) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.member r
r Map r (Map c a)
rm
hasColumn :: Ord c => Table r c a -> c -> Bool
hasColumn :: Table r c a -> c -> Bool
hasColumn (Table (Map r (Map c a)
_, Map c (Map r a)
cm, Int
_)) c
c = c -> Map c (Map r a) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.member c
c Map c (Map r a)
cm
null :: Table r c a -> Bool
null :: Table r c a -> Bool
null (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = Map r (Map c a) -> Bool
forall k a. Map k a -> Bool
Map.null Map r (Map c a)
rm
notNull :: Table r c a -> Bool
notNull :: Table r c a -> Bool
notNull = Bool -> Bool
not (Bool -> Bool) -> (Table r c a -> Bool) -> Table r c a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Table r c a -> Bool
forall r c a. Table r c a -> Bool
null
size :: Table r c a -> Int
size :: Table r c a -> Int
size (Table (Map r (Map c a)
_, Map c (Map r a)
_, Int
sz)) = Int
sz
union :: (Ord r, Ord c) => Table r c a -> Table r c a -> Table r c a
union :: Table r c a -> Table r c a -> Table r c a
union = (a -> a -> a) -> Table r c a -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
(a -> a -> a) -> Table r c a -> Table r c a -> Table r c a
unionWith a -> a -> a
forall a b. a -> b -> a
const
unions :: (Foldable f, Ord r, Ord c) => f (Table r c a) -> Table r c a
unions :: f (Table r c a) -> Table r c a
unions = (Table r c a -> Table r c a -> Table r c a)
-> Table r c a -> f (Table r c a) -> Table r c a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr Table r c a -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
Table r c a -> Table r c a -> Table r c a
union Table r c a
forall r c a. Table r c a
empty
unionWith :: (Ord r, Ord c) => (a -> a -> a) -> Table r c a -> Table r c a -> Table r c a
unionWith :: (a -> a -> a) -> Table r c a -> Table r c a -> Table r c a
unionWith = (r -> c -> a -> a -> a)
-> Table r c a -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
(r -> c -> a -> a -> a)
-> Table r c a -> Table r c a -> Table r c a
unionWithKeys ((r -> c -> a -> a -> a)
-> Table r c a -> Table r c a -> Table r c a)
-> ((a -> a -> a) -> r -> c -> a -> a -> a)
-> (a -> a -> a)
-> Table r c a
-> Table r c a
-> Table r c a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> a -> a) -> r -> c -> a -> a -> a
forall a b. a -> b -> a
const ((c -> a -> a -> a) -> r -> c -> a -> a -> a)
-> ((a -> a -> a) -> c -> a -> a -> a)
-> (a -> a -> a)
-> r
-> c
-> a
-> a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a -> a) -> c -> a -> a -> a
forall a b. a -> b -> a
const
unionWithKeys
:: (Ord r, Ord c)
=> (r -> c -> a -> a -> a)
-> Table r c a -> Table r c a -> Table r c a
unionWithKeys :: (r -> c -> a -> a -> a)
-> Table r c a -> Table r c a -> Table r c a
unionWithKeys r -> c -> a -> a -> a
f (Table (Map r (Map c a)
rm1, Map c (Map r a)
cm1, Int
_)) (Table (Map r (Map c a)
rm2, Map c (Map r a)
cm2, Int
_)) = Map r (Map c a) -> Map c (Map r a) -> Table r c a
forall r c a. Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps Map r (Map c a)
rm Map c (Map r a)
cm
where
rm :: Map r (Map c a)
rm = (r -> Map c a -> Map c a -> Map c a)
-> Map r (Map c a) -> Map r (Map c a) -> Map r (Map c a)
forall k a.
Ord k =>
(k -> a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWithKey ((c -> a -> a -> a) -> Map c a -> Map c a -> Map c a
forall k a.
Ord k =>
(k -> a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWithKey ((c -> a -> a -> a) -> Map c a -> Map c a -> Map c a)
-> (r -> c -> a -> a -> a) -> r -> Map c a -> Map c a -> Map c a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c -> a -> a -> a
f) Map r (Map c a)
rm1 Map r (Map c a)
rm2
cm :: Map c (Map r a)
cm = (c -> Map r a -> Map r a -> Map r a)
-> Map c (Map r a) -> Map c (Map r a) -> Map c (Map r a)
forall k a.
Ord k =>
(k -> a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWithKey ((r -> a -> a -> a) -> Map r a -> Map r a -> Map r a
forall k a.
Ord k =>
(k -> a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWithKey ((r -> a -> a -> a) -> Map r a -> Map r a -> Map r a)
-> (c -> r -> a -> a -> a) -> c -> Map r a -> Map r a -> Map r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> c -> a -> a -> a) -> c -> r -> a -> a -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip r -> c -> a -> a -> a
f) Map c (Map r a)
cm1 Map c (Map r a)
cm2
unionsWith :: (Foldable f, Ord r, Ord c) => (a -> a -> a) -> f (Table r c a) -> Table r c a
unionsWith :: (a -> a -> a) -> f (Table r c a) -> Table r c a
unionsWith a -> a -> a
f = (Table r c a -> Table r c a -> Table r c a)
-> Table r c a -> f (Table r c a) -> Table r c a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr ((a -> a -> a) -> Table r c a -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
(a -> a -> a) -> Table r c a -> Table r c a -> Table r c a
unionWith a -> a -> a
f) Table r c a
forall r c a. Table r c a
empty
unionsWithKeys
:: (Foldable f, Ord r, Ord c)
=> (r -> c -> a -> a -> a)
-> f (Table r c a) -> Table r c a
unionsWithKeys :: (r -> c -> a -> a -> a) -> f (Table r c a) -> Table r c a
unionsWithKeys r -> c -> a -> a -> a
f = (Table r c a -> Table r c a -> Table r c a)
-> Table r c a -> f (Table r c a) -> Table r c a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Foldable.foldr ((r -> c -> a -> a -> a)
-> Table r c a -> Table r c a -> Table r c a
forall r c a.
(Ord r, Ord c) =>
(r -> c -> a -> a -> a)
-> Table r c a -> Table r c a -> Table r c a
unionWithKeys r -> c -> a -> a -> a
f) Table r c a
forall r c a. Table r c a
empty
difference :: (Ord r, Ord c) => Table r c a -> Table r c a -> Table r c a
difference :: Table r c a -> Table r c a -> Table r c a
difference (Table (Map r (Map c a)
rm1, Map c (Map r a)
cm1, Int
_)) (Table (Map r (Map c a)
rm2, Map c (Map r a)
cm2, Int
_)) = Map r (Map c a) -> Map c (Map r a) -> Table r c a
forall r c a. Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps Map r (Map c a)
rm Map c (Map r a)
cm
where
rm :: Map r (Map c a)
rm = (Map c a -> Map c a -> Maybe (Map c a))
-> Map r (Map c a) -> Map r (Map c a) -> Map r (Map c a)
forall k a b.
Ord k =>
(a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a
Map.differenceWith ((Map c a -> Maybe (Map c a)
forall a. a -> Maybe a
Just (Map c a -> Maybe (Map c a))
-> (Map c a -> Map c a) -> Map c a -> Maybe (Map c a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Map c a -> Map c a) -> Map c a -> Maybe (Map c a))
-> (Map c a -> Map c a -> Map c a)
-> Map c a
-> Map c a
-> Maybe (Map c a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map c a -> Map c a -> Map c a
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.difference) Map r (Map c a)
rm1 Map r (Map c a)
rm2
cm :: Map c (Map r a)
cm = (Map r a -> Map r a -> Maybe (Map r a))
-> Map c (Map r a) -> Map c (Map r a) -> Map c (Map r a)
forall k a b.
Ord k =>
(a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a
Map.differenceWith ((Map r a -> Maybe (Map r a)
forall a. a -> Maybe a
Just (Map r a -> Maybe (Map r a))
-> (Map r a -> Map r a) -> Map r a -> Maybe (Map r a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Map r a -> Map r a) -> Map r a -> Maybe (Map r a))
-> (Map r a -> Map r a -> Map r a)
-> Map r a
-> Map r a
-> Maybe (Map r a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map r a -> Map r a -> Map r a
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.difference) Map c (Map r a)
cm1 Map c (Map r a)
cm2
map :: (a -> b) -> Table r c a -> Table r c b
map :: (a -> b) -> Table r c a -> Table r c b
map = (r -> c -> a -> b) -> Table r c a -> Table r c b
forall r c a b. (r -> c -> a -> b) -> Table r c a -> Table r c b
mapWithKeys ((r -> c -> a -> b) -> Table r c a -> Table r c b)
-> ((a -> b) -> r -> c -> a -> b)
-> (a -> b)
-> Table r c a
-> Table r c b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> b) -> r -> c -> a -> b
forall a b. a -> b -> a
const ((c -> a -> b) -> r -> c -> a -> b)
-> ((a -> b) -> c -> a -> b) -> (a -> b) -> r -> c -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> c -> a -> b
forall a b. a -> b -> a
const
mapWithKeys :: (r -> c -> a -> b) -> Table r c a -> Table r c b
mapWithKeys :: (r -> c -> a -> b) -> Table r c a -> Table r c b
mapWithKeys r -> c -> a -> b
f (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
sz)) = (Map r (Map c b), Map c (Map r b), Int) -> Table r c b
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map r (Map c b)
rm', Map c (Map r b)
cm', Int
sz)
where
rm' :: Map r (Map c b)
rm' = (r -> Map c a -> Map c b) -> Map r (Map c a) -> Map r (Map c b)
forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey ((c -> a -> b) -> Map c a -> Map c b
forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey ((c -> a -> b) -> Map c a -> Map c b)
-> (r -> c -> a -> b) -> r -> Map c a -> Map c b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c -> a -> b
f) Map r (Map c a)
rm
cm' :: Map c (Map r b)
cm' = (c -> Map r a -> Map r b) -> Map c (Map r a) -> Map c (Map r b)
forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey ((r -> a -> b) -> Map r a -> Map r b
forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey ((r -> a -> b) -> Map r a -> Map r b)
-> (c -> r -> a -> b) -> c -> Map r a -> Map r b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> c -> a -> b) -> c -> r -> a -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip r -> c -> a -> b
f) Map c (Map r a)
cm
traverseWithKeys
:: (Applicative t, Ord r, Ord c)
=> (r -> c -> a -> t b)
-> Table r c a
-> t (Table r c b)
traverseWithKeys :: (r -> c -> a -> t b) -> Table r c a -> t (Table r c b)
traverseWithKeys r -> c -> a -> t b
f (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = Map r (Map c b) -> Map c (Map r b) -> Table r c b
forall r c a. Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps (Map r (Map c b) -> Map c (Map r b) -> Table r c b)
-> t (Map r (Map c b)) -> t (Map c (Map r b) -> Table r c b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t (Map r (Map c b))
rm' t (Map c (Map r b) -> Table r c b)
-> t (Map c (Map r b)) -> t (Table r c b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> t (Map c (Map r b))
cm'
where
rm' :: t (Map r (Map c b))
rm' = (r -> Map c a -> t (Map c b))
-> Map r (Map c a) -> t (Map r (Map c b))
forall (t :: * -> *) k a b.
Applicative t =>
(k -> a -> t b) -> Map k a -> t (Map k b)
Map.traverseWithKey ((c -> a -> t b) -> Map c a -> t (Map c b)
forall (t :: * -> *) k a b.
Applicative t =>
(k -> a -> t b) -> Map k a -> t (Map k b)
Map.traverseWithKey ((c -> a -> t b) -> Map c a -> t (Map c b))
-> (r -> c -> a -> t b) -> r -> Map c a -> t (Map c b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c -> a -> t b
f) Map r (Map c a)
rm
cm' :: t (Map c (Map r b))
cm' = Map r (Map c b) -> Map c (Map r b)
forall r c a. (Ord r, Ord c) => Map r (Map c a) -> Map c (Map r a)
transpose' (Map r (Map c b) -> Map c (Map r b))
-> t (Map r (Map c b)) -> t (Map c (Map r b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t (Map r (Map c b))
rm'
traverseMaybeWithKeys
:: (Applicative t, Ord r, Ord c)
=> (r -> c -> a -> t (Maybe b))
-> Table r c a
-> t (Table r c b)
traverseMaybeWithKeys :: (r -> c -> a -> t (Maybe b)) -> Table r c a -> t (Table r c b)
traverseMaybeWithKeys r -> c -> a -> t (Maybe b)
f (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = Map r (Map c b) -> Map c (Map r b) -> Table r c b
forall r c a. Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps (Map r (Map c b) -> Map c (Map r b) -> Table r c b)
-> t (Map r (Map c b)) -> t (Map c (Map r b) -> Table r c b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t (Map r (Map c b))
rm' t (Map c (Map r b) -> Table r c b)
-> t (Map c (Map r b)) -> t (Table r c b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> t (Map c (Map r b))
cm'
where
rm' :: t (Map r (Map c b))
rm' = (r -> Map c a -> t (Map c b))
-> Map r (Map c a) -> t (Map r (Map c b))
forall (t :: * -> *) k a b.
Applicative t =>
(k -> a -> t b) -> Map k a -> t (Map k b)
Map.traverseWithKey ((c -> a -> t (Maybe b)) -> Map c a -> t (Map c b)
forall (f :: * -> *) k a b.
Applicative f =>
(k -> a -> f (Maybe b)) -> Map k a -> f (Map k b)
Map.traverseMaybeWithKey ((c -> a -> t (Maybe b)) -> Map c a -> t (Map c b))
-> (r -> c -> a -> t (Maybe b)) -> r -> Map c a -> t (Map c b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c -> a -> t (Maybe b)
f) Map r (Map c a)
rm
cm' :: t (Map c (Map r b))
cm' = Map r (Map c b) -> Map c (Map r b)
forall r c a. (Ord r, Ord c) => Map r (Map c a) -> Map c (Map r a)
transpose' (Map r (Map c b) -> Map c (Map r b))
-> t (Map r (Map c b)) -> t (Map c (Map r b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t (Map r (Map c b))
rm'
foldr :: (a -> b -> b) -> b -> Table r c a -> b
foldr :: (a -> b -> b) -> b -> Table r c a -> b
foldr = (r -> c -> a -> b -> b) -> b -> Table r c a -> b
forall r c a b. (r -> c -> a -> b -> b) -> b -> Table r c a -> b
foldrWithKeys ((r -> c -> a -> b -> b) -> b -> Table r c a -> b)
-> ((a -> b -> b) -> r -> c -> a -> b -> b)
-> (a -> b -> b)
-> b
-> Table r c a
-> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> b -> b) -> r -> c -> a -> b -> b
forall a b. a -> b -> a
const ((c -> a -> b -> b) -> r -> c -> a -> b -> b)
-> ((a -> b -> b) -> c -> a -> b -> b)
-> (a -> b -> b)
-> r
-> c
-> a
-> b
-> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b -> b) -> c -> a -> b -> b
forall a b. a -> b -> a
const
foldl :: (a -> b -> a) -> a -> Table r c b -> a
foldl :: (a -> b -> a) -> a -> Table r c b -> a
foldl a -> b -> a
f = (a -> r -> c -> b -> a) -> a -> Table r c b -> a
forall a r c b. (a -> r -> c -> b -> a) -> a -> Table r c b -> a
foldlWithKeys (\a
a r
_ c
_ -> a -> b -> a
f a
a)
foldrWithKeys :: (r -> c -> a -> b -> b) -> b -> Table r c a -> b
foldrWithKeys :: (r -> c -> a -> b -> b) -> b -> Table r c a -> b
foldrWithKeys r -> c -> a -> b -> b
f b
b (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = (r -> Map c a -> b -> b) -> b -> Map r (Map c a) -> b
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey r -> Map c a -> b -> b
f' b
b Map r (Map c a)
rm
where
f' :: r -> Map c a -> b -> b
f' = (b -> Map c a -> b) -> Map c a -> b -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((b -> Map c a -> b) -> Map c a -> b -> b)
-> (r -> b -> Map c a -> b) -> r -> Map c a -> b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> b -> b) -> b -> Map c a -> b
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey ((c -> a -> b -> b) -> b -> Map c a -> b)
-> (r -> c -> a -> b -> b) -> r -> b -> Map c a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c -> a -> b -> b
f
foldlWithKeys :: (a -> r -> c -> b -> a) -> a -> Table r c b -> a
foldlWithKeys :: (a -> r -> c -> b -> a) -> a -> Table r c b -> a
foldlWithKeys a -> r -> c -> b -> a
f a
a (Table (Map r (Map c b)
rm, Map c (Map r b)
_, Int
_)) = (a -> r -> Map c b -> a) -> a -> Map r (Map c b) -> a
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey a -> r -> Map c b -> a
f' a
a Map r (Map c b)
rm
where
f' :: a -> r -> Map c b -> a
f' = (r -> a -> Map c b -> a) -> a -> r -> Map c b -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> c -> b -> a) -> a -> Map c b -> a
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey ((a -> c -> b -> a) -> a -> Map c b -> a)
-> (r -> a -> c -> b -> a) -> r -> a -> Map c b -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> r -> c -> b -> a) -> r -> a -> c -> b -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> r -> c -> b -> a
f)
foldr' :: (a -> b -> b) -> b -> Table r c a -> b
foldr' :: (a -> b -> b) -> b -> Table r c a -> b
foldr' = (r -> c -> a -> b -> b) -> b -> Table r c a -> b
forall r c a b. (r -> c -> a -> b -> b) -> b -> Table r c a -> b
foldrWithKeys' ((r -> c -> a -> b -> b) -> b -> Table r c a -> b)
-> ((a -> b -> b) -> r -> c -> a -> b -> b)
-> (a -> b -> b)
-> b
-> Table r c a
-> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> b -> b) -> r -> c -> a -> b -> b
forall a b. a -> b -> a
const ((c -> a -> b -> b) -> r -> c -> a -> b -> b)
-> ((a -> b -> b) -> c -> a -> b -> b)
-> (a -> b -> b)
-> r
-> c
-> a
-> b
-> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b -> b) -> c -> a -> b -> b
forall a b. a -> b -> a
const
foldl' :: (a -> b -> a) -> a -> Table r c b -> a
foldl' :: (a -> b -> a) -> a -> Table r c b -> a
foldl' a -> b -> a
f = (a -> r -> c -> b -> a) -> a -> Table r c b -> a
forall a r c b. (a -> r -> c -> b -> a) -> a -> Table r c b -> a
foldlWithKeys' (\a
a r
_ c
_ -> a -> b -> a
f a
a)
foldrWithKeys' :: (r -> c -> a -> b -> b) -> b -> Table r c a -> b
foldrWithKeys' :: (r -> c -> a -> b -> b) -> b -> Table r c a -> b
foldrWithKeys' r -> c -> a -> b -> b
f b
b (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = (r -> Map c a -> b -> b) -> b -> Map r (Map c a) -> b
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey' r -> Map c a -> b -> b
f' b
b Map r (Map c a)
rm
where
f' :: r -> Map c a -> b -> b
f' = (b -> Map c a -> b) -> Map c a -> b -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((b -> Map c a -> b) -> Map c a -> b -> b)
-> (r -> b -> Map c a -> b) -> r -> Map c a -> b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> b -> b) -> b -> Map c a -> b
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey' ((c -> a -> b -> b) -> b -> Map c a -> b)
-> (r -> c -> a -> b -> b) -> r -> b -> Map c a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c -> a -> b -> b
f
foldlWithKeys' :: (a -> r -> c -> b -> a) -> a -> Table r c b -> a
foldlWithKeys' :: (a -> r -> c -> b -> a) -> a -> Table r c b -> a
foldlWithKeys' a -> r -> c -> b -> a
f a
a (Table (Map r (Map c b)
rm, Map c (Map r b)
_, Int
_)) = (a -> r -> Map c b -> a) -> a -> Map r (Map c b) -> a
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' a -> r -> Map c b -> a
f' a
a Map r (Map c b)
rm
where
f' :: a -> r -> Map c b -> a
f' = (r -> a -> Map c b -> a) -> a -> r -> Map c b -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> c -> b -> a) -> a -> Map c b -> a
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' ((a -> c -> b -> a) -> a -> Map c b -> a)
-> (r -> a -> c -> b -> a) -> r -> a -> Map c b -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> r -> c -> b -> a) -> r -> a -> c -> b -> a
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> r -> c -> b -> a
f)
foldMapWithKeys :: Monoid m => (r -> c -> a -> m) -> Table r c a -> m
foldMapWithKeys :: (r -> c -> a -> m) -> Table r c a -> m
foldMapWithKeys r -> c -> a -> m
f (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = (r -> Map c a -> m) -> Map r (Map c a) -> m
forall m k a. Monoid m => (k -> a -> m) -> Map k a -> m
Map.foldMapWithKey r -> Map c a -> m
f' Map r (Map c a)
rm
where
f' :: r -> Map c a -> m
f' = (c -> a -> m) -> Map c a -> m
forall m k a. Monoid m => (k -> a -> m) -> Map k a -> m
Map.foldMapWithKey ((c -> a -> m) -> Map c a -> m)
-> (r -> c -> a -> m) -> r -> Map c a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c -> a -> m
f
row :: Ord r => r -> Table r c a -> Map c a
row :: r -> Table r c a -> Map c a
row r
r (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = Map c a -> r -> Map r (Map c a) -> Map c a
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault Map c a
forall k a. Map k a
Map.empty r
r Map r (Map c a)
rm
column :: Ord c => c -> Table r c a -> Map r a
column :: c -> Table r c a -> Map r a
column c
c (Table (Map r (Map c a)
_, Map c (Map r a)
cm, Int
_)) = Map r a -> c -> Map c (Map r a) -> Map r a
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault Map r a
forall k a. Map k a
Map.empty c
c Map c (Map r a)
cm
rowMap :: Table r c a -> Map r (Map c a)
rowMap :: Table r c a -> Map r (Map c a)
rowMap (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = Map r (Map c a)
rm
columnMap :: Table r c a -> Map c (Map r a)
columnMap :: Table r c a -> Map c (Map r a)
columnMap (Table (Map r (Map c a)
_, Map c (Map r a)
cm, Int
_)) = Map c (Map r a)
cm
rowKeys :: Table r c a -> [r]
rowKeys :: Table r c a -> [r]
rowKeys (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = Map r (Map c a) -> [r]
forall k a. Map k a -> [k]
Map.keys Map r (Map c a)
rm
columnKeys :: Table r c a -> [c]
columnKeys :: Table r c a -> [c]
columnKeys (Table (Map r (Map c a)
_, Map c (Map r a)
cm, Int
_)) = Map c (Map r a) -> [c]
forall k a. Map k a -> [k]
Map.keys Map c (Map r a)
cm
rowKeysSet :: Table r c a -> Set r
rowKeysSet :: Table r c a -> Set r
rowKeysSet (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = Map r (Map c a) -> Set r
forall k a. Map k a -> Set k
Map.keysSet Map r (Map c a)
rm
columnKeysSet :: Table r c a -> Set c
columnKeysSet :: Table r c a -> Set c
columnKeysSet (Table (Map r (Map c a)
_, Map c (Map r a)
cm, Int
_)) = Map c (Map r a) -> Set c
forall k a. Map k a -> Set k
Map.keysSet Map c (Map r a)
cm
toList :: Table r c a -> [(r, c, a)]
toList :: Table r c a -> [(r, c, a)]
toList (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = Map r [(c, a)] -> [(r, [(c, a)])]
forall k a. Map k a -> [(k, a)]
Map.toList (Map c a -> [(c, a)]
forall k a. Map k a -> [(k, a)]
Map.toList (Map c a -> [(c, a)]) -> Map r (Map c a) -> Map r [(c, a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map r (Map c a)
rm) [(r, [(c, a)])] -> ((r, [(c, a)]) -> [(r, c, a)]) -> [(r, c, a)]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (r, [(c, a)]) -> [(r, c, a)]
forall a b c. (a, [(b, c)]) -> [(a, b, c)]
distr
toRowAscList :: Table r c a -> [(r, c, a)]
toRowAscList :: Table r c a -> [(r, c, a)]
toRowAscList (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = Map r [(c, a)] -> [(r, [(c, a)])]
forall k a. Map k a -> [(k, a)]
Map.toAscList (Map c a -> [(c, a)]
forall k a. Map k a -> [(k, a)]
Map.toAscList (Map c a -> [(c, a)]) -> Map r (Map c a) -> Map r [(c, a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map r (Map c a)
rm) [(r, [(c, a)])] -> ((r, [(c, a)]) -> [(r, c, a)]) -> [(r, c, a)]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (r, [(c, a)]) -> [(r, c, a)]
forall a b c. (a, [(b, c)]) -> [(a, b, c)]
distr
toColumnAscList :: Table r c a -> [(c, r, a)]
toColumnAscList :: Table r c a -> [(c, r, a)]
toColumnAscList (Table (Map r (Map c a)
_, Map c (Map r a)
cm, Int
_)) = Map c [(r, a)] -> [(c, [(r, a)])]
forall k a. Map k a -> [(k, a)]
Map.toAscList (Map r a -> [(r, a)]
forall k a. Map k a -> [(k, a)]
Map.toAscList (Map r a -> [(r, a)]) -> Map c (Map r a) -> Map c [(r, a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map c (Map r a)
cm) [(c, [(r, a)])] -> ((c, [(r, a)]) -> [(c, r, a)]) -> [(c, r, a)]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (c, [(r, a)]) -> [(c, r, a)]
forall a b c. (a, [(b, c)]) -> [(a, b, c)]
distr
toRowDescList :: Table r c a -> [(r, c, a)]
toRowDescList :: Table r c a -> [(r, c, a)]
toRowDescList (Table (Map r (Map c a)
rm, Map c (Map r a)
_, Int
_)) = Map r [(c, a)] -> [(r, [(c, a)])]
forall k a. Map k a -> [(k, a)]
Map.toDescList (Map c a -> [(c, a)]
forall k a. Map k a -> [(k, a)]
Map.toDescList (Map c a -> [(c, a)]) -> Map r (Map c a) -> Map r [(c, a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map r (Map c a)
rm) [(r, [(c, a)])] -> ((r, [(c, a)]) -> [(r, c, a)]) -> [(r, c, a)]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (r, [(c, a)]) -> [(r, c, a)]
forall a b c. (a, [(b, c)]) -> [(a, b, c)]
distr
toColumnDescList :: Table r c a -> [(c, r, a)]
toColumnDescList :: Table r c a -> [(c, r, a)]
toColumnDescList (Table (Map r (Map c a)
_, Map c (Map r a)
cm, Int
_)) = Map c [(r, a)] -> [(c, [(r, a)])]
forall k a. Map k a -> [(k, a)]
Map.toDescList (Map r a -> [(r, a)]
forall k a. Map k a -> [(k, a)]
Map.toDescList (Map r a -> [(r, a)]) -> Map c (Map r a) -> Map c [(r, a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map c (Map r a)
cm) [(c, [(r, a)])] -> ((c, [(r, a)]) -> [(c, r, a)]) -> [(c, r, a)]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (c, [(r, a)]) -> [(c, r, a)]
forall a b c. (a, [(b, c)]) -> [(a, b, c)]
distr
filter :: (a -> Bool) -> Table r c a -> Table r c a
filter :: (a -> Bool) -> Table r c a -> Table r c a
filter = (r -> c -> a -> Bool) -> Table r c a -> Table r c a
forall r c a. (r -> c -> a -> Bool) -> Table r c a -> Table r c a
filterWithKeys ((r -> c -> a -> Bool) -> Table r c a -> Table r c a)
-> ((a -> Bool) -> r -> c -> a -> Bool)
-> (a -> Bool)
-> Table r c a
-> Table r c a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> Bool) -> r -> c -> a -> Bool
forall a b. a -> b -> a
const ((c -> a -> Bool) -> r -> c -> a -> Bool)
-> ((a -> Bool) -> c -> a -> Bool)
-> (a -> Bool)
-> r
-> c
-> a
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Bool) -> c -> a -> Bool
forall a b. a -> b -> a
const
filterRow :: (r -> Bool) -> Table r c a -> Table r c a
filterRow :: (r -> Bool) -> Table r c a -> Table r c a
filterRow r -> Bool
p (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
_)) = (Map r (Map c a), Map c (Map r a), Int) -> Table r c a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map r (Map c a)
rm', Map c (Map r a) -> Map c (Map r a)
forall k1 k2 a. Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty Map c (Map r a)
cm', Map r (Map c a) -> Int
forall k1 k2 a. Map k1 (Map k2 a) -> Int
size' Map r (Map c a)
rm')
where
rm' :: Map r (Map c a)
rm' = (r -> Map c a -> Bool) -> Map r (Map c a) -> Map r (Map c a)
forall k a. (k -> a -> Bool) -> Map k a -> Map k a
Map.filterWithKey (Bool -> Map c a -> Bool
forall a b. a -> b -> a
const (Bool -> Map c a -> Bool) -> (r -> Bool) -> r -> Map c a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> Bool
p) Map r (Map c a)
rm
cm' :: Map c (Map r a)
cm' = (Map r a -> Map r a) -> Map c (Map r a) -> Map c (Map r a)
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map ((r -> a -> Bool) -> Map r a -> Map r a
forall k a. (k -> a -> Bool) -> Map k a -> Map k a
Map.filterWithKey (Bool -> a -> Bool
forall a b. a -> b -> a
const (Bool -> a -> Bool) -> (r -> Bool) -> r -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> Bool
p)) Map c (Map r a)
cm
filterColumn :: (c -> Bool) -> Table r c a -> Table r c a
filterColumn :: (c -> Bool) -> Table r c a -> Table r c a
filterColumn c -> Bool
p (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
_)) = (Map r (Map c a), Map c (Map r a), Int) -> Table r c a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map r (Map c a) -> Map r (Map c a)
forall k1 k2 a. Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty Map r (Map c a)
rm', Map c (Map r a)
cm', Map c (Map r a) -> Int
forall k1 k2 a. Map k1 (Map k2 a) -> Int
size' Map c (Map r a)
cm')
where
rm' :: Map r (Map c a)
rm' = (Map c a -> Map c a) -> Map r (Map c a) -> Map r (Map c a)
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map ((c -> a -> Bool) -> Map c a -> Map c a
forall k a. (k -> a -> Bool) -> Map k a -> Map k a
Map.filterWithKey (Bool -> a -> Bool
forall a b. a -> b -> a
const (Bool -> a -> Bool) -> (c -> Bool) -> c -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> Bool
p)) Map r (Map c a)
rm
cm' :: Map c (Map r a)
cm' = (c -> Map r a -> Bool) -> Map c (Map r a) -> Map c (Map r a)
forall k a. (k -> a -> Bool) -> Map k a -> Map k a
Map.filterWithKey (Bool -> Map r a -> Bool
forall a b. a -> b -> a
const (Bool -> Map r a -> Bool) -> (c -> Bool) -> c -> Map r a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> Bool
p) Map c (Map r a)
cm
filterWithKeys
:: (r -> c -> a -> Bool)
-> Table r c a
-> Table r c a
filterWithKeys :: (r -> c -> a -> Bool) -> Table r c a -> Table r c a
filterWithKeys r -> c -> a -> Bool
p (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
_)) = Map r (Map c a) -> Map c (Map r a) -> Table r c a
forall r c a. Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps Map r (Map c a)
rm' Map c (Map r a)
cm'
where
rm' :: Map r (Map c a)
rm' = (r -> Map c a -> Map c a) -> Map r (Map c a) -> Map r (Map c a)
forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey ((c -> a -> Bool) -> Map c a -> Map c a
forall k a. (k -> a -> Bool) -> Map k a -> Map k a
Map.filterWithKey ((c -> a -> Bool) -> Map c a -> Map c a)
-> (r -> c -> a -> Bool) -> r -> Map c a -> Map c a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c -> a -> Bool
p) Map r (Map c a)
rm
cm' :: Map c (Map r a)
cm' = (c -> Map r a -> Map r a) -> Map c (Map r a) -> Map c (Map r a)
forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey ((r -> a -> Bool) -> Map r a -> Map r a
forall k a. (k -> a -> Bool) -> Map k a -> Map k a
Map.filterWithKey ((r -> a -> Bool) -> Map r a -> Map r a)
-> (c -> r -> a -> Bool) -> c -> Map r a -> Map r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> c -> a -> Bool) -> c -> r -> a -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip r -> c -> a -> Bool
p) Map c (Map r a)
cm
mapMaybe :: (a -> Maybe b) -> Table r c a -> Table r c b
mapMaybe :: (a -> Maybe b) -> Table r c a -> Table r c b
mapMaybe = (r -> c -> a -> Maybe b) -> Table r c a -> Table r c b
forall r c a b.
(r -> c -> a -> Maybe b) -> Table r c a -> Table r c b
mapMaybeWithKeys ((r -> c -> a -> Maybe b) -> Table r c a -> Table r c b)
-> ((a -> Maybe b) -> r -> c -> a -> Maybe b)
-> (a -> Maybe b)
-> Table r c a
-> Table r c b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> Maybe b) -> r -> c -> a -> Maybe b
forall a b. a -> b -> a
const ((c -> a -> Maybe b) -> r -> c -> a -> Maybe b)
-> ((a -> Maybe b) -> c -> a -> Maybe b)
-> (a -> Maybe b)
-> r
-> c
-> a
-> Maybe b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Maybe b) -> c -> a -> Maybe b
forall a b. a -> b -> a
const
mapMaybeWithKeys :: (r -> c -> a -> Maybe b) -> Table r c a -> Table r c b
mapMaybeWithKeys :: (r -> c -> a -> Maybe b) -> Table r c a -> Table r c b
mapMaybeWithKeys r -> c -> a -> Maybe b
f (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
_)) = Map r (Map c b) -> Map c (Map r b) -> Table r c b
forall r c a. Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps Map r (Map c b)
rm' Map c (Map r b)
cm'
where
rm' :: Map r (Map c b)
rm' = (r -> Map c a -> Map c b) -> Map r (Map c a) -> Map r (Map c b)
forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey ((c -> a -> Maybe b) -> Map c a -> Map c b
forall k a b. (k -> a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybeWithKey ((c -> a -> Maybe b) -> Map c a -> Map c b)
-> (r -> c -> a -> Maybe b) -> r -> Map c a -> Map c b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c -> a -> Maybe b
f) Map r (Map c a)
rm
cm' :: Map c (Map r b)
cm' = (c -> Map r a -> Map r b) -> Map c (Map r a) -> Map c (Map r b)
forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey ((r -> a -> Maybe b) -> Map r a -> Map r b
forall k a b. (k -> a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybeWithKey ((r -> a -> Maybe b) -> Map r a -> Map r b)
-> (c -> r -> a -> Maybe b) -> c -> Map r a -> Map r b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> c -> a -> Maybe b) -> c -> r -> a -> Maybe b
forall a b c. (a -> b -> c) -> b -> a -> c
flip r -> c -> a -> Maybe b
f) Map c (Map r a)
cm
mapEither :: (a -> Either a1 a2) -> Table r c a -> (Table r c a1, Table r c a2)
mapEither :: (a -> Either a1 a2) -> Table r c a -> (Table r c a1, Table r c a2)
mapEither = (r -> c -> a -> Either a1 a2)
-> Table r c a -> (Table r c a1, Table r c a2)
forall r c a a1 a2.
(r -> c -> a -> Either a1 a2)
-> Table r c a -> (Table r c a1, Table r c a2)
mapEitherWithKeys ((r -> c -> a -> Either a1 a2)
-> Table r c a -> (Table r c a1, Table r c a2))
-> ((a -> Either a1 a2) -> r -> c -> a -> Either a1 a2)
-> (a -> Either a1 a2)
-> Table r c a
-> (Table r c a1, Table r c a2)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> Either a1 a2) -> r -> c -> a -> Either a1 a2
forall a b. a -> b -> a
const ((c -> a -> Either a1 a2) -> r -> c -> a -> Either a1 a2)
-> ((a -> Either a1 a2) -> c -> a -> Either a1 a2)
-> (a -> Either a1 a2)
-> r
-> c
-> a
-> Either a1 a2
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Either a1 a2) -> c -> a -> Either a1 a2
forall a b. a -> b -> a
const
mapEitherWithKeys :: (r -> c -> a -> Either a1 a2) -> Table r c a -> (Table r c a1, Table r c a2)
mapEitherWithKeys :: (r -> c -> a -> Either a1 a2)
-> Table r c a -> (Table r c a1, Table r c a2)
mapEitherWithKeys r -> c -> a -> Either a1 a2
f (Table (Map r (Map c a)
rm, Map c (Map r a)
cm, Int
_)) = (Map r (Map c a1) -> Map c (Map r a1) -> Table r c a1
forall r c a. Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps Map r (Map c a1)
rm1 Map c (Map r a1)
cm1, Map r (Map c a2) -> Map c (Map r a2) -> Table r c a2
forall r c a. Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps Map r (Map c a2)
rm2 Map c (Map r a2)
cm2)
where
(Map r (Map c a1)
rm1, Map r (Map c a2)
rm2) = (((Map c a1, Map c a2) -> Map c a1)
-> Map r (Map c a1, Map c a2) -> Map r (Map c a1)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Map c a1, Map c a2) -> Map c a1
forall a b. (a, b) -> a
fst (Map r (Map c a1, Map c a2) -> Map r (Map c a1))
-> (Map r (Map c a1, Map c a2) -> Map r (Map c a2))
-> Map r (Map c a1, Map c a2)
-> (Map r (Map c a1), Map r (Map c a2))
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& ((Map c a1, Map c a2) -> Map c a2)
-> Map r (Map c a1, Map c a2) -> Map r (Map c a2)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Map c a1, Map c a2) -> Map c a2
forall a b. (a, b) -> b
snd) (Map r (Map c a1, Map c a2)
-> (Map r (Map c a1), Map r (Map c a2)))
-> Map r (Map c a1, Map c a2)
-> (Map r (Map c a1), Map r (Map c a2))
forall a b. (a -> b) -> a -> b
$ (r -> Map c a -> (Map c a1, Map c a2))
-> Map r (Map c a) -> Map r (Map c a1, Map c a2)
forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey ((c -> a -> Either a1 a2) -> Map c a -> (Map c a1, Map c a2)
forall k a b c.
(k -> a -> Either b c) -> Map k a -> (Map k b, Map k c)
Map.mapEitherWithKey ((c -> a -> Either a1 a2) -> Map c a -> (Map c a1, Map c a2))
-> (r -> c -> a -> Either a1 a2)
-> r
-> Map c a
-> (Map c a1, Map c a2)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r -> c -> a -> Either a1 a2
f) Map r (Map c a)
rm
(Map c (Map r a1)
cm1, Map c (Map r a2)
cm2) = (((Map r a1, Map r a2) -> Map r a1)
-> Map c (Map r a1, Map r a2) -> Map c (Map r a1)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Map r a1, Map r a2) -> Map r a1
forall a b. (a, b) -> a
fst (Map c (Map r a1, Map r a2) -> Map c (Map r a1))
-> (Map c (Map r a1, Map r a2) -> Map c (Map r a2))
-> Map c (Map r a1, Map r a2)
-> (Map c (Map r a1), Map c (Map r a2))
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& ((Map r a1, Map r a2) -> Map r a2)
-> Map c (Map r a1, Map r a2) -> Map c (Map r a2)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Map r a1, Map r a2) -> Map r a2
forall a b. (a, b) -> b
snd) (Map c (Map r a1, Map r a2)
-> (Map c (Map r a1), Map c (Map r a2)))
-> Map c (Map r a1, Map r a2)
-> (Map c (Map r a1), Map c (Map r a2))
forall a b. (a -> b) -> a -> b
$ (c -> Map r a -> (Map r a1, Map r a2))
-> Map c (Map r a) -> Map c (Map r a1, Map r a2)
forall k a b. (k -> a -> b) -> Map k a -> Map k b
Map.mapWithKey ((r -> a -> Either a1 a2) -> Map r a -> (Map r a1, Map r a2)
forall k a b c.
(k -> a -> Either b c) -> Map k a -> (Map k b, Map k c)
Map.mapEitherWithKey ((r -> a -> Either a1 a2) -> Map r a -> (Map r a1, Map r a2))
-> (c -> r -> a -> Either a1 a2)
-> c
-> Map r a
-> (Map r a1, Map r a2)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> c -> a -> Either a1 a2) -> c -> r -> a -> Either a1 a2
forall a b c. (a -> b -> c) -> b -> a -> c
flip r -> c -> a -> Either a1 a2
f) Map c (Map r a)
cm
assoc :: (a, (b, c)) -> (a, b, c)
assoc :: (a, (b, c)) -> (a, b, c)
assoc (a
a, (b
b, c
c)) = (a
a, b
b, c
c)
distr :: (a, [(b, c)]) -> [(a, b, c)]
distr :: (a, [(b, c)]) -> [(a, b, c)]
distr = ((a, (b, c)) -> (a, b, c)) -> [(a, (b, c))] -> [(a, b, c)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, (b, c)) -> (a, b, c)
forall a b c. (a, (b, c)) -> (a, b, c)
assoc ([(a, (b, c))] -> [(a, b, c)])
-> ((a, [(b, c)]) -> [(a, (b, c))]) -> (a, [(b, c)]) -> [(a, b, c)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> [(b, c)] -> [(a, (b, c))]) -> (a, [(b, c)]) -> [(a, (b, c))]
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ([a] -> [(b, c)] -> [(a, (b, c))]
forall a b. [a] -> [b] -> [(a, b)]
zip ([a] -> [(b, c)] -> [(a, (b, c))])
-> (a -> [a]) -> a -> [(b, c)] -> [(a, (b, c))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a]
forall a. a -> [a]
repeat)
fromMaps :: Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps :: Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps Map r (Map c a)
rm Map c (Map r a)
cm = (Map r (Map c a), Map c (Map r a), Int) -> Table r c a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map r (Map c a)
rm', Map c (Map r a)
cm', Map r (Map c a) -> Int
forall k1 k2 a. Map k1 (Map k2 a) -> Int
size' Map r (Map c a)
rm')
where
rm' :: Map r (Map c a)
rm' = Map r (Map c a) -> Map r (Map c a)
forall k1 k2 a. Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty Map r (Map c a)
rm
cm' :: Map c (Map r a)
cm' = Map c (Map r a) -> Map c (Map r a)
forall k1 k2 a. Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty Map c (Map r a)
cm
fromMaps' :: (Ord r, Ord c) => r -> c -> Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps' :: r -> c -> Map r (Map c a) -> Map c (Map r a) -> Table r c a
fromMaps' r
r c
c Map r (Map c a)
rm Map c (Map r a)
cm = (Map r (Map c a), Map c (Map r a), Int) -> Table r c a
forall r c a.
(Map r (Map c a), Map c (Map r a), Int) -> Table r c a
Table (Map r (Map c a)
rm', Map c (Map r a)
cm', Map r (Map c a) -> Int
forall k1 k2 a. Map k1 (Map k2 a) -> Int
size' Map r (Map c a)
rm')
where
rm' :: Map r (Map c a)
rm' = r -> Map r (Map c a) -> Map r (Map c a)
forall k1 k2 a.
Ord k1 =>
k1 -> Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty' r
r Map r (Map c a)
rm
cm' :: Map c (Map r a)
cm' = c -> Map c (Map r a) -> Map c (Map r a)
forall k1 k2 a.
Ord k1 =>
k1 -> Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty' c
c Map c (Map r a)
cm
nonEmpty :: Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty :: Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty = (Map k2 a -> Bool) -> Map k1 (Map k2 a) -> Map k1 (Map k2 a)
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Bool -> Bool
not (Bool -> Bool) -> (Map k2 a -> Bool) -> Map k2 a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k2 a -> Bool
forall k a. Map k a -> Bool
Map.null)
nonEmpty' :: Ord k1 => k1 -> Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty' :: k1 -> Map k1 (Map k2 a) -> Map k1 (Map k2 a)
nonEmpty' k1
k1 Map k1 (Map k2 a)
m = case k1 -> Map k1 (Map k2 a) -> Maybe (Map k2 a)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k1
k1 Map k1 (Map k2 a)
m of
Just Map k2 a
m' | Map k2 a -> Bool
forall k a. Map k a -> Bool
Map.null Map k2 a
m' -> k1 -> Map k1 (Map k2 a) -> Map k1 (Map k2 a)
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete k1
k1 Map k1 (Map k2 a)
m
Maybe (Map k2 a)
_ -> Map k1 (Map k2 a)
m
transpose' :: (Ord r, Ord c) => Map r (Map c a) -> Map c (Map r a)
transpose' :: Map r (Map c a) -> Map c (Map r a)
transpose' = (r -> Map c a -> Map c (Map r a) -> Map c (Map r a))
-> Map c (Map r a) -> Map r (Map c a) -> Map c (Map r a)
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey' r -> Map c a -> Map c (Map r a) -> Map c (Map r a)
forall k k a.
(Ord k, Ord k) =>
k -> Map k a -> Map k (Map k a) -> Map k (Map k a)
f Map c (Map r a)
forall k a. Map k a
Map.empty
where
f :: k -> Map k a -> Map k (Map k a) -> Map k (Map k a)
f k
r = (Map k a -> Map k a -> Map k a)
-> Map k (Map k a) -> Map k (Map k a) -> Map k (Map k a)
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith Map k a -> Map k a -> Map k a
forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union (Map k (Map k a) -> Map k (Map k a) -> Map k (Map k a))
-> (Map k a -> Map k (Map k a))
-> Map k a
-> Map k (Map k a)
-> Map k (Map k a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Map k a) -> Map k a -> Map k (Map k a)
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (k -> a -> Map k a
forall k a. k -> a -> Map k a
Map.singleton k
r)
size' :: Map k1 (Map k2 a) -> Int
size' :: Map k1 (Map k2 a) -> Int
size' = Map k1 Int -> Int
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum (Map k1 Int -> Int)
-> (Map k1 (Map k2 a) -> Map k1 Int) -> Map k1 (Map k2 a) -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map k2 a -> Int) -> Map k1 (Map k2 a) -> Map k1 Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map k2 a -> Int
forall k a. Map k a -> Int
Map.size
uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 a -> b -> c -> d
f ~(a
a, b
b, c
c) = a -> b -> c -> d
f a
a b
b c
c