primus-0.3.0.0: nonempty and positive functions
Copyright(c) Grant Weyburne 2022
LicenseBSD-3
Safe HaskellSafe-Inferred
LanguageHaskell2010

Primus.Enum

Description

 
Synopsis

enumerations

universe1 :: forall a. (Bounded a, Enum a) => NonEmpty a Source #

create a nonempty list of all the values for an Enum

universe1R :: forall a. (Bounded a, Enum a) => NonEmpty a Source #

create a nonempty list of all the values for an Enum in reverse order

enumFrom1 :: (Bounded a, Enum a) => a -> NonEmpty a Source #

create a nonempty list of values starting at "a"

enumFrom1R :: forall a. (Bounded a, Enum a) => a -> NonEmpty a Source #

create a nonempty list of "a" in reverse order

enumTo1 :: (Bounded a, Enum a) => a -> NonEmpty a Source #

create a nonempty list of values starting at "a"

enumFromThen1 :: (Bounded a, Enum a) => a -> a -> NonEmpty a Source #

create a nonempty list of values starting at "a" and skipping "b"

enumFromTo1 :: Enum a => a -> a -> NonEmpty a Source #

create a nonempty list of values starting at "a" and skipping "b"

enumFromThenTo1 :: Enum a => a -> a -> a -> NonEmpty a Source #

enumFromThenTo for nonempty lists

converters

predSafe :: (Bounded a, Enum a) => a -> Maybe a Source #

safe pred for a bounded Enum

succSafe :: (Bounded a, Enum a) => a -> Maybe a Source #

safe succ for a bounded Enum

integerToEnumSafe :: forall a. (Enum a, Bounded a) => Integer -> Either String a Source #

safe toEnum

integerToIntSafe :: Integer -> Either String Int Source #

concrete safe conversion of Integer to Int

container enums

enumerations

toEnumList :: forall a. (Enum a, Bounded a) => Integer -> Either String [a] Source #

convert toEnum of "a" into a list containing "a"s zero is the empty list: see toEnumList

toEnumList1 :: forall a. (Enum a, Bounded a) => Integer -> Either String (NonEmpty a) Source #

convert toEnum of "a" into a nonempty list containing "a"s

universeTraversable :: forall f a. (Traversable f, Enum a, Bounded a) => f a -> Either String (NonEmpty (f a)) Source #

generate all the possible enum combinations for the given container in ascending order

useful for creating all the valid indices for matrices

toEnumTraversable :: forall a f z. (Traversable f, Enum a, Bounded a) => f z -> Integer -> Either String (f a) Source #

load a given container with "a"s using the relative position "i"

converters

succTraversable :: forall a t. (Traversable t, Enum a, Bounded a) => t a -> Either String (t a) Source #

succ for a traversable container

predTraversable :: forall a t. (Traversable t, Enum a, Bounded a) => t a -> Either String (t a) Source #

pred for a traversable container

fromEnumFoldable :: forall a t. (Foldable t, Enum a, Bounded a) => t a -> Either String Integer Source #

reverse of toEnumList [can fail if xs is null and toEnum 0 is not defined]

fromEnumFoldable1 :: forall a t. (Foldable1 t, Enum a, Bounded a) => t a -> Integer Source #

reverse of toEnumList1 [cant fail]

capacity

capacity :: forall a t z. (Bounded a, Enum a, Foldable t) => t z -> Either String (Integer, Integer) Source #

calculates the minimum and maximum range of enumerations that can be stored in a container of the given size