Module
Data.Enum
- Package
- purescript-enums
- Repository
- purescript/purescript-enums
#Cardinality Source
newtype Cardinality a
Constructors
Instances
Newtype (Cardinality a) _
Eq (Cardinality a)
Ord (Cardinality a)
#Enum Source
#defaultSucc Source
defaultSucc :: forall a. (Int -> Maybe a) -> (a -> Int) -> a -> Maybe a
defaultSucc toEnum fromEnum = succ
#defaultPred Source
defaultPred :: forall a. (Int -> Maybe a) -> (a -> Int) -> a -> Maybe a
defaultPred toEnum fromEnum = pred
#enumFromTo Source
enumFromTo :: forall u a. Enum a => Unfoldable u => a -> a -> u a
Returns a successive sequence of elements from the lower bound to the upper bound (inclusive).
#enumFromThenTo Source
enumFromThenTo :: forall a. BoundedEnum a => a -> a -> a -> Array a
[a,b..c]
#upFrom Source
upFrom :: forall u a. Enum a => Unfoldable u => a -> u a
#downFrom Source
downFrom :: forall u a. Enum a => Unfoldable u => a -> u a
#BoundedEnum Source
class (Bounded a, Enum a) <= BoundedEnum a where
Type class for finite enumerations.
This should not be considered a part of a numeric hierarchy, as in Haskell.
Rather, this is a type class for small, ordered sum types with
statically-determined cardinality and the ability to easily compute
successor and predecessor elements, e.g. DayOfWeek
.
Laws:
succ bottom >>= succ >>= succ ... succ [cardinality - 1 times] == top
pred top >>= pred >>= pred ... pred [cardinality - 1 times] == bottom
forall a > bottom: pred a >>= succ == Just a
forall a < top: succ a >>= pred == Just a
forall a > bottom: fromEnum <$> pred a = Just (fromEnum a - 1)
forall a < top: fromEnum <$> succ a = Just (fromEnum a + 1)
e1 `compare` e2 == fromEnum e1 `compare` fromEnum e2
toEnum (fromEnum a) = Just a
Members
cardinality :: Cardinality a
toEnum :: Int -> Maybe a
fromEnum :: a -> Int
Instances
BoundedEnum Boolean
BoundedEnum Char
BoundedEnum Unit
BoundedEnum Ordering
(BoundedEnum a) => BoundedEnum (Maybe a)
(BoundedEnum a, BoundedEnum b) => BoundedEnum (Either a b)
(BoundedEnum a, BoundedEnum b) => BoundedEnum (Tuple a b)
#defaultCardinality Source
defaultCardinality :: forall a. Bounded a => Enum a => Cardinality a
Runs in O(n)
where n
is fromEnum top
#defaultToEnum Source
defaultToEnum :: forall a. Bounded a => Enum a => Int -> Maybe a
Runs in O(n)
where n
is fromEnum a
#defaultFromEnum Source
defaultFromEnum :: forall a. Enum a => a -> Int
Runs in O(n)
where n
is fromEnum a
#toEnumWithDefaults Source
toEnumWithDefaults :: forall a. BoundedEnum a => a -> a -> Int -> a
Like toEnum
but returns the first argument if x
is less than
fromEnum bottom
and the second argument if x
is greater than
fromEnum top
.
toEnumWithDefaults False True (-1) -- False
toEnumWithDefaults False True 0 -- False
toEnumWithDefaults False True 1 -- True
toEnumWithDefaults False True 2 -- True
- Modules
- Data.
Enum