brick-2.9: A declarative terminal user interface library

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.IMap

Synopsis

- data IMap a
- data Run a = Run {
  - len :: !Int
  - val :: !a
  }
- empty :: IMap a
- null :: IMap a -> Bool
- singleton :: Int -> Run a -> IMap a
- insert :: Int -> Run a -> IMap a -> IMap a
- delete :: Int -> Run ignored -> IMap a -> IMap a
- restrict :: Int -> Run ignored -> IMap a -> IMap a
- lookup :: Int -> IMap a -> Maybe a
- splitLE :: Int -> IMap a -> (IMap a, IMap a)
- intersectionWith :: (a -> b -> c) -> IMap a -> IMap b -> IMap c
- mapMaybe :: (a -> Maybe b) -> IMap a -> IMap b
- addToKeys :: Int -> IMap a -> IMap a
- unsafeUnion :: IMap a -> IMap a -> IMap a
- fromList :: [(Int, Run a)] -> IMap a
- unsafeRuns :: IMap a -> IntMap (Run a)
- unsafeToAscList :: IMap a -> [(Int, Run a)]

# Documentation

data IMap a Source #

Semantically, `IMap` and `IntMap` are identical; but `IMap` is more efficient when large sequences of contiguous keys are mapped to the same value.

#### Instances

Instances details

Applicative IMap Source # | Zippy: `(<*>)` combines values at equal keys, discarding any values whose key is in only one of its two arguments.
Instance details Defined in Data.IMap Methods pure :: a -> IMap a Source # (<*>) :: IMap (a -> b) -> IMap a -> IMap b Source # liftA2 :: (a -> b -> c) -> IMap a -> IMap b -> IMap c Source # (*>) :: IMap a -> IMap b -> IMap b Source # (<*) :: IMap a -> IMap b -> IMap a Source #
Functor IMap Source # |
Instance details Defined in Data.IMap Methods fmap :: (a -> b) -> IMap a -> IMap b Source # (<$) :: a -> IMap b -> IMap a Source #
NFData a => NFData (IMap a) Source # |
Instance details Defined in Data.IMap Methods rnf :: IMap a -> () Source #
Generic (IMap a) Source # |

Instance details

Defined in Data.IMap

Associated Types

type Rep (IMap a) |
Instance details Defined in Data.IMap type Rep (IMap a) = D1 ('MetaData "IMap" "Data.IMap" "brick-2.9-B6MumQsEfTbKCFLiQ2o79Q" 'True) (C1 ('MetaCons "IMap" 'PrefixI 'True) (S1 ('MetaSel ('Just "_runs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (IntMap (Run a)))))

Methods

from :: IMap a -> Rep (IMap a) x Source #

to :: Rep (IMap a) x -> IMap a Source #

Read a => Read (IMap a) Source # |
Instance details Defined in Data.IMap Methods readsPrec :: Int -> ReadS (IMap a) Source # readList :: ReadS [IMap a] Source # readPrec :: ReadPrec (IMap a) Source # readListPrec :: ReadPrec [IMap a] Source #
Show a => Show (IMap a) Source # |
Instance details Defined in Data.IMap Methods showsPrec :: Int -> IMap a -> ShowS Source # show :: IMap a -> String Source # showList :: [IMap a] -> ShowS Source #
Eq a => Eq (IMap a) Source # |
Instance details Defined in Data.IMap Methods (==) :: IMap a -> IMap a -> Bool Source # (/=) :: IMap a -> IMap a -> Bool Source #
Ord a => Ord (IMap a) Source # |
Instance details Defined in Data.IMap Methods compare :: IMap a -> IMap a -> Ordering Source # (<) :: IMap a -> IMap a -> Bool Source # (<=) :: IMap a -> IMap a -> Bool Source # (>) :: IMap a -> IMap a -> Bool Source # (>=) :: IMap a -> IMap a -> Bool Source # max :: IMap a -> IMap a -> IMap a Source # min :: IMap a -> IMap a -> IMap a Source #
type Rep (IMap a) Source # |
Instance details Defined in Data.IMap type Rep (IMap a) = D1 ('MetaData "IMap" "Data.IMap" "brick-2.9-B6MumQsEfTbKCFLiQ2o79Q" 'True) (C1 ('MetaCons "IMap" 'PrefixI 'True) (S1 ('MetaSel ('Just "_runs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (IntMap (Run a)))))

data Run a Source #

`Run n a` represents `n` copies of the value `a`.

Constructors

Run |

Fields

- len :: !Int
- val :: !a

#### Instances

Instances details

Functor Run Source # |
Instance details Defined in Data.IMap Methods fmap :: (a -> b) -> Run a -> Run b Source # (<$) :: a -> Run b -> Run a Source #
Foldable Run Source # |

Instance details

Defined in Data.IMap

Methods

fold :: Monoid m => Run m -> m Source #

foldMap :: Monoid m => (a -> m) -> Run a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Run a -> m Source #

foldr :: (a -> b -> b) -> b -> Run a -> b Source #

foldr' :: (a -> b -> b) -> b -> Run a -> b Source #

foldl :: (b -> a -> b) -> b -> Run a -> b Source #

foldl' :: (b -> a -> b) -> b -> Run a -> b Source #

foldr1 :: (a -> a -> a) -> Run a -> a Source #

foldl1 :: (a -> a -> a) -> Run a -> a Source #

toList :: Run a -> [a] Source #

null :: Run a -> Bool Source #

length :: Run a -> Int Source #

elem :: Eq a => a -> Run a -> Bool Source #

maximum :: Ord a => Run a -> a Source #

minimum :: Ord a => Run a -> a Source #

sum :: Num a => Run a -> a Source #

product :: Num a => Run a -> a Source #

Traversable Run Source # |
Instance details Defined in Data.IMap Methods traverse :: Applicative f => (a -> f b) -> Run a -> f (Run b) Source # sequenceA :: Applicative f => Run (f a) -> f (Run a) Source # mapM :: Monad m => (a -> m b) -> Run a -> m (Run b) Source # sequence :: Monad m => Run (m a) -> m (Run a) Source #
NFData a => NFData (Run a) Source # |
Instance details Defined in Data.IMap Methods rnf :: Run a -> () Source #
Generic (Run a) Source # |

Instance details

Defined in Data.IMap

Associated Types

type Rep (Run a) |
Instance details Defined in Data.IMap type Rep (Run a) = D1 ('MetaData "Run" "Data.IMap" "brick-2.9-B6MumQsEfTbKCFLiQ2o79Q" 'False) (C1 ('MetaCons "Run" 'PrefixI 'True) (S1 ('MetaSel ('Just "len") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "val") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)))

Methods

from :: Run a -> Rep (Run a) x Source #

to :: Rep (Run a) x -> Run a Source #

Read a => Read (Run a) Source # |
Instance details Defined in Data.IMap Methods readsPrec :: Int -> ReadS (Run a) Source # readList :: ReadS [Run a] Source # readPrec :: ReadPrec (Run a) Source # readListPrec :: ReadPrec [Run a] Source #
Show a => Show (Run a) Source # |
Instance details Defined in Data.IMap Methods showsPrec :: Int -> Run a -> ShowS Source # show :: Run a -> String Source # showList :: [Run a] -> ShowS Source #
Eq a => Eq (Run a) Source # |
Instance details Defined in Data.IMap Methods (==) :: Run a -> Run a -> Bool Source # (/=) :: Run a -> Run a -> Bool Source #
Ord a => Ord (Run a) Source # |
Instance details Defined in Data.IMap Methods compare :: Run a -> Run a -> Ordering Source # (<) :: Run a -> Run a -> Bool Source # (<=) :: Run a -> Run a -> Bool Source # (>) :: Run a -> Run a -> Bool Source # (>=) :: Run a -> Run a -> Bool Source # max :: Run a -> Run a -> Run a Source # min :: Run a -> Run a -> Run a Source #
type Rep (Run a) Source # |
Instance details Defined in Data.IMap type Rep (Run a) = D1 ('MetaData "Run" "Data.IMap" "brick-2.9-B6MumQsEfTbKCFLiQ2o79Q" 'False) (C1 ('MetaCons "Run" 'PrefixI 'True) (S1 ('MetaSel ('Just "len") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Just "val") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)))

empty :: IMap a Source #

null :: IMap a -> Bool Source #

singleton :: Int -> Run a -> IMap a Source #

insert :: Int -> Run a -> IMap a -> IMap a Source #

delete :: Int -> Run ignored -> IMap a -> IMap a Source #

restrict :: Int -> Run ignored -> IMap a -> IMap a Source #

Given a range of keys (as specified by a starting key and a length for consistency with other functions in this module), restrict the map to keys in that range. `restrict k r m` is equivalent to `intersectionWith const m (insert k r empty)` but potentially more efficient.

lookup :: Int -> IMap a -> Maybe a Source #

splitLE :: Int -> IMap a -> (IMap a, IMap a) Source #

`splitLE n m` produces a tuple `(le, gt)` where `le` has all the associations of `m` where the keys are `<= n` and `gt` has all the associations of `m` where the keys are `> n`.

intersectionWith :: (a -> b -> c) -> IMap a -> IMap b -> IMap c Source #

mapMaybe :: (a -> Maybe b) -> IMap a -> IMap b Source #

addToKeys :: Int -> IMap a -> IMap a Source #

Increment all keys by the given amount. This is like `mapKeysMonotonic`, but restricted to partially-applied addition.

unsafeUnion :: IMap a -> IMap a -> IMap a Source #

This function is unsafe because it assumes there is no overlap between its arguments. That is, in the call `unsafeUnion a b`, the caller must guarantee that if `lookup k a = Just v` then `lookup k b = Nothing` and vice versa.

fromList :: [(Int, Run a)] -> IMap a Source #

unsafeRuns :: IMap a -> IntMap (Run a) Source #

This function is unsafe because `IMap`s that compare equal may split their runs into different chunks; consumers must promise that they do not treat run boundaries specially.

unsafeToAscList :: IMap a -> [(Int, Run a)] Source #

This function is unsafe because `IMap`s that compare equal may split their runs into different chunks; consumers must promise that they do not treat run boundaries specially.