mappings-0.3.1.0: Types which represent functions k -> v
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Mapping.Piecewise

Synopsis

Documentation

data Piecewise k v Source #

A data structure storing mappings that are constant on intervals.

If the space of keys not discrete, then these mappings are right-continuous: values are in general defined on intervals $a leq x < b$ which are closed on the left and open on the right.

Constructors

Piecewise 

Fields

Instances

Instances details
Ord k => Mapping k (Piecewise k) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

cst :: v -> Piecewise k v Source #

act :: Piecewise k v -> k -> v Source #

isConst :: Ord v => Piecewise k v -> Maybe v Source #

mtraverse :: (Applicative f, Ord v) => (u -> f v) -> Piecewise k u -> f (Piecewise k v) Source #

mmap :: Ord v => (u -> v) -> Piecewise k u -> Piecewise k v Source #

mergeA :: (Applicative f, Ord w) => (u -> v -> f w) -> Piecewise k u -> Piecewise k v -> f (Piecewise k w) Source #

merge :: Ord w => (u -> v -> w) -> Piecewise k u -> Piecewise k v -> Piecewise k w Source #

Foldable (Piecewise k) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

fold :: Monoid m => Piecewise k m -> m #

foldMap :: Monoid m => (a -> m) -> Piecewise k a -> m #

foldMap' :: Monoid m => (a -> m) -> Piecewise k a -> m #

foldr :: (a -> b -> b) -> b -> Piecewise k a -> b #

foldr' :: (a -> b -> b) -> b -> Piecewise k a -> b #

foldl :: (b -> a -> b) -> b -> Piecewise k a -> b #

foldl' :: (b -> a -> b) -> b -> Piecewise k a -> b #

foldr1 :: (a -> a -> a) -> Piecewise k a -> a #

foldl1 :: (a -> a -> a) -> Piecewise k a -> a #

toList :: Piecewise k a -> [a] #

null :: Piecewise k a -> Bool #

length :: Piecewise k a -> Int #

elem :: Eq a => a -> Piecewise k a -> Bool #

maximum :: Ord a => Piecewise k a -> a #

minimum :: Ord a => Piecewise k a -> a #

sum :: Num a => Piecewise k a -> a #

product :: Num a => Piecewise k a -> a #

Eq k => Functor (Piecewise k) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

fmap :: (a -> b) -> Piecewise k a -> Piecewise k b #

(<$) :: a -> Piecewise k b -> Piecewise k a #

Neighbourly (Piecewise k) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

neighbours :: Ord v => Piecewise k v -> Set (v, v) Source #

(Ord k, Ord b, Monoid b) => Monoid (Piecewise k b) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

mempty :: Piecewise k b #

mappend :: Piecewise k b -> Piecewise k b -> Piecewise k b #

mconcat :: [Piecewise k b] -> Piecewise k b #

(Ord k, Ord b, Semigroup b) => Semigroup (Piecewise k b) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

(<>) :: Piecewise k b -> Piecewise k b -> Piecewise k b #

sconcat :: NonEmpty (Piecewise k b) -> Piecewise k b #

stimes :: Integral b0 => b0 -> Piecewise k b -> Piecewise k b #

(Ord k, Ord b, Num b) => Num (Piecewise k b) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

(+) :: Piecewise k b -> Piecewise k b -> Piecewise k b #

(-) :: Piecewise k b -> Piecewise k b -> Piecewise k b #

(*) :: Piecewise k b -> Piecewise k b -> Piecewise k b #

negate :: Piecewise k b -> Piecewise k b #

abs :: Piecewise k b -> Piecewise k b #

signum :: Piecewise k b -> Piecewise k b #

fromInteger :: Integer -> Piecewise k b #

(Show k, Show v) => Show (Piecewise k v) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

showsPrec :: Int -> Piecewise k v -> ShowS #

show :: Piecewise k v -> String #

showList :: [Piecewise k v] -> ShowS #

(Ord k, Ord b, Boolean b) => Boolean (Piecewise k b) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

true :: Piecewise k b #

false :: Piecewise k b #

not :: Piecewise k b -> Piecewise k b #

(&&) :: Piecewise k b -> Piecewise k b -> Piecewise k b #

(||) :: Piecewise k b -> Piecewise k b -> Piecewise k b #

xor :: Piecewise k b -> Piecewise k b -> Piecewise k b #

(-->) :: Piecewise k b -> Piecewise k b -> Piecewise k b #

(<-->) :: Piecewise k b -> Piecewise k b -> Piecewise k b #

(Eq v, Eq k) => Eq (Piecewise k v) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

(==) :: Piecewise k v -> Piecewise k v -> Bool #

(/=) :: Piecewise k v -> Piecewise k v -> Bool #

(Ord v, Ord k) => Ord (Piecewise k v) Source # 
Instance details

Defined in Data.Mapping.Piecewise

Methods

compare :: Piecewise k v -> Piecewise k v -> Ordering #

(<) :: Piecewise k v -> Piecewise k v -> Bool #

(<=) :: Piecewise k v -> Piecewise k v -> Bool #

(>) :: Piecewise k v -> Piecewise k v -> Bool #

(>=) :: Piecewise k v -> Piecewise k v -> Bool #

max :: Piecewise k v -> Piecewise k v -> Piecewise k v #

min :: Piecewise k v -> Piecewise k v -> Piecewise k v #

rightEnd :: Piecewise k v -> v Source #

The value taken for sufficiently large keys

fromAscList :: Eq v => v -> [(k, v)] -> Piecewise k v Source #

Assumes the keys are distinct and increasing (but consecutive values may be the same, in which case the intervening keys are removed)

fromAscListUnsafe :: v -> [(k, v)] -> Piecewise k v Source #

Assumes that the keys are distinct and increasing, and also that consecutive values are distinct

changeAt :: v -> k -> v -> Piecewise k v Source #

Takes value a for keys less than x and b otherwise

greaterThanOrEqual :: k -> Piecewise k Bool Source #

Is the value greater than or equal to k?

lessThan :: k -> Piecewise k Bool Source #

Is the value less than k?

greaterThan :: Enum k => k -> Piecewise k Bool Source #

Is the value greater than k? This is subject to the usual concerns about Enum (it not to be used with floating-point arithmetic, for example)

lessThanOrEqual :: Enum k => k -> Piecewise k Bool Source #

Is the value less than or equal to k? This is subject to the usual concerns about Enum (it not to be used with floating-point arithmetic, for example)

values :: Piecewise k v -> [v] Source #

All values, in order of increasing key

mapKeysMonotonic :: (k -> l) -> Piecewise k v -> Piecewise l v Source #

Alter keys according to a function, assumed to be monotone (not checked)

mapKeysAntitonic :: (k -> l) -> Piecewise k v -> Piecewise l v Source #

Alter keys according to a function, assumed to be antitone (not checked)

splitPiecewise :: Ord k => k -> Piecewise k v -> (Piecewise k v, Piecewise k v) Source #

Split in two: one which assumes keys are less than k, and one which assumes them greater than or equal to k.

gluePiecewise :: Eq v => Piecewise k v -> k -> Piecewise k v -> Piecewise k v Source #

Assemble two maps; it is assumed that all keys in the left-hand map are less than k and all keys in the right-hand map are greater than or equal to k (which is not checked).

mjoin :: (Ord k, Eq w) => (v -> Piecewise k w) -> Piecewise k v -> Piecewise k w Source #

This is almost a monad (with cst as pure) except that we need an Eq instance on the values.