alex
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Ranged.Ranges

Description

A range has an upper and lower boundary.

Synopsis

Construction

data Range v Source #

A Range has upper and lower boundaries.

Constructors

Range 

Instances

Instances details
(Show a, DiscreteOrdered a) => Show (Range a) Source # 
Instance details

Defined in Data.Ranged.Ranges

Methods

showsPrec :: Int -> Range a -> ShowS #

show :: Range a -> String #

showList :: [Range a] -> ShowS #

DiscreteOrdered a => Eq (Range a) Source # 
Instance details

Defined in Data.Ranged.Ranges

Methods

(==) :: Range a -> Range a -> Bool #

(/=) :: Range a -> Range a -> Bool #

DiscreteOrdered a => Ord (Range a) Source # 
Instance details

Defined in Data.Ranged.Ranges

Methods

compare :: Range a -> Range a -> Ordering #

(<) :: Range a -> Range a -> Bool #

(<=) :: Range a -> Range a -> Bool #

(>) :: Range a -> Range a -> Bool #

(>=) :: Range a -> Range a -> Bool #

max :: Range a -> Range a -> Range a #

min :: Range a -> Range a -> Range a #

emptyRange :: Range v Source #

The empty range

fullRange :: Range v Source #

The full range. All values are within it.

Predicates

rangeIsEmpty :: DiscreteOrdered v => Range v -> Bool Source #

A range is empty unless its upper boundary is greater than its lower boundary.

rangeIsFull :: DiscreteOrdered v => Range v -> Bool Source #

A range is full if it contains every possible value.

rangeOverlap :: DiscreteOrdered v => Range v -> Range v -> Bool Source #

Two ranges overlap if their intersection is non-empty.

rangeEncloses :: DiscreteOrdered v => Range v -> Range v -> Bool Source #

The first range encloses the second if every value in the second range is also within the first range. If the second range is empty then this is always true.

rangeSingletonValue :: DiscreteOrdered v => Range v -> Maybe v Source #

If the range is a singleton, returns Just the value. Otherwise returns Nothing.

Known bug: This always returns Nothing for ranges including BoundaryBelowAll or BoundaryAboveAll. For bounded types this can be incorrect. For instance, the following range only contains one value:

   Range (BoundaryBelow maxBound) BoundaryAboveAll

Membership

rangeHas :: Ord v => Range v -> v -> Bool Source #

True if the value is within the range.

rangeListHas :: Ord v => [Range v] -> v -> Bool Source #

True if the value is within one of the ranges.

Set Operations

singletonRange :: v -> Range v Source #

A range containing a single value

rangeIntersection :: DiscreteOrdered v => Range v -> Range v -> Range v Source #

Intersection of two ranges, if any.

rangeUnion :: DiscreteOrdered v => Range v -> Range v -> [Range v] Source #

Union of two ranges. Returns one or two results.

If there are two results then they are guaranteed to have a non-empty gap in between, but may not be in ascending order.

rangeDifference :: DiscreteOrdered v => Range v -> Range v -> [Range v] Source #

range1 minus range2. Returns zero, one or two results. Multiple results are guaranteed to have non-empty gaps in between, but may not be in ascending order.