digit-0.6: A data-type representing digits 0-9 and other combinations

Safe HaskellNone
LanguageHaskell2010

Data.Digit.Integral

Contents

Synopsis

Binary

integralBinaryNoZero :: (Integral a, BinaryNoZero d) => Prism' a d Source #

>>> 1 ^? integralBinaryNoZero
Just BinDigit1
>>> integralBinaryNoZero # BinDigit1 :: Integer
1

integralBinary :: (Integral a, Binary d) => Prism' a d Source #

>>> 0 ^? integralBinary :: Maybe BinDigit
Just BinDigit0
>>> integralBinary # BinDigit0 :: Integer
0

integralBinDigits :: Integral a => a -> Either (NonEmpty BinDigit) (NonEmpty BinDigit) Source #

>>> integralBinDigits (4 :: Int)
Right (BinDigit1 :| [BinDigit0, BinDigit0])
>>> integralBinDigits (0 :: Int)
Right (BinDigit0 :| [])
>>> integralBinDigits (-1 :: Int)
Left (BinDigit0 :| [])
>>> integralBinDigits (-4 :: Int)
Left (BinDigit1 :| [BinDigit1])

binDigitsIntegral :: Integral a => Either (NonEmpty BinDigit) (NonEmpty BinDigit) -> a Source #

>>> binDigitsIntegral (Right (BinDigit1 :| [BinDigit0, BinDigit0])) :: Int
4
>>> binDigitsIntegral (Right (BinDigit0 :| [])) :: Int
0
>>> binDigitsIntegral (Left (BinDigit0 :| [])) :: Int
-1
>>> binDigitsIntegral (Left (BinDigit1 :| [BinDigit1])) :: Int
-4

Octal

integralOctalNoZero :: (Integral a, OctalNoZero d) => Prism' a d Source #

>>> 7 ^? integralOctalNoZero :: Maybe OctDigit
Just OctDigit7
>>> integralOctalNoZero # OctDigit7 :: Integer
7

integralOctal :: (Integral a, Octal d) => Prism' a d Source #

>>> 7 ^? integralOctal :: Maybe OctDigit
Just OctDigit7
>>> integralOctal # OctDigit7 :: Integer
7

integralOctDigits :: Integral a => a -> Either (NonEmpty OctDigit) (NonEmpty OctDigit) Source #

>>> integralOctDigits (64 :: Int)
Right (OctDigit1 :| [OctDigit0, OctDigit0])
>>> integralOctDigits (0 :: Int)
Right (OctDigit0 :| [])
>>> integralOctDigits (-1 :: Int)
Left (OctDigit0 :| [])
>>> integralOctDigits (-64 :: Int)
Left (OctDigit7 :| [OctDigit7])

octDigitsIntegral :: Integral a => Either (NonEmpty OctDigit) (NonEmpty OctDigit) -> a Source #

>>> octDigitsIntegral (Right (OctDigit1 :| [OctDigit0, OctDigit0])) :: Int
64
>>> octDigitsIntegral (Right (OctDigit0 :| [])) :: Int
0
>>> octDigitsIntegral (Left (OctDigit0 :| [])) :: Int
-1
>>> octDigitsIntegral (Left (OctDigit7 :| [OctDigit7])) :: Int
-64

Decimal

integralDecimal :: (Integral a, Decimal d) => Prism' a d Source #

>>> 9 ^? integralDecimal :: Maybe DecDigit
Just DecDigit9
>>> integralDecimal # DecDigit9 :: Integer
9

integralDecimalNoZero :: (Integral a, DecimalNoZero d) => Prism' a d Source #

>>> 9 ^? integralDecimalNoZero :: Maybe DecDigit
Just DecDigit9
>>> integralDecimalNoZero # DecDigit9 :: Integer
9

integralDecDigits :: Integral a => a -> Either (NonEmpty DecDigit) (NonEmpty DecDigit) Source #

>>> integralDecDigits (100 :: Int)
Right (DecDigit1 :| [DecDigit0, DecDigit0])
>>> integralDecDigits (0 :: Int)
Right (DecDigit0 :| [])
>>> integralDecDigits (-1 :: Int)
Left (DecDigit0 :| [])
>>> integralDecDigits (-100 :: Int)
Left (DecDigit9 :| [DecDigit9])

decDigitsIntegral :: Integral a => Either (NonEmpty DecDigit) (NonEmpty DecDigit) -> a Source #

>>> decDigitsIntegral (Right (DecDigit1 :| [DecDigit0, DecDigit0])) :: Int
100
>>> decDigitsIntegral (Right (DecDigit0 :| [])) :: Int
0
>>> decDigitsIntegral (Left (DecDigit0 :| [])) :: Int
-1
>>> decDigitsIntegral (Left (DecDigit9 :| [DecDigit9])) :: Int
-100

Hexadecimal

integralHexadecimalNoZero :: (Integral a, HexadecimalNoZero d) => Prism' a d Source #

>>> 15 ^? integralHexadecimalNoZero :: Maybe HexDigit
Just HexDigitf
>>> integralHexadecimalNoZero # HexDigitf :: Integer
15

integralHexadecimal :: (Integral a, Hexadecimal d) => Prism' a d Source #

>>> 15 ^? integralHexadecimal :: Maybe HexDigit
Just HexDigitf
>>> integralHexadecimal # HexDigitf :: Integer
15

integralHexDigits :: Integral a => a -> Either (NonEmpty HexDigit) (NonEmpty HexDigit) Source #

>>> integralHexDigits (256 :: Int)
Right (HexDigit1 :| [HexDigit0, HexDigit0])
>>> integralHexDigits (0 :: Int)
Right (HexDigit0 :| [])
>>> integralHexDigits (-1 :: Int)
Left (HexDigit0 :| [])
>>> integralHexDigits (-256 :: Int)
Left (HexDigitf :| [HexDigitf])

hexDigitsIntegral :: Integral a => Either (NonEmpty HexDigit) (NonEmpty HexDigit) -> a Source #

>>> hexDigitsIntegral (Right (HexDigit1 :| [HexDigit0, HexDigit0])) :: Int
256
>>> hexDigitsIntegral (Right (HexDigit0 :| [])) :: Int
0
>>> hexDigitsIntegral (Left (HexDigit0 :| [])) :: Int
-1
>>> hexDigitsIntegral (Left (HexDigitf :| [HexDigitf])) :: Int
-256

HEXADECIMAL

integralHEXADECIMALNoZero :: (Integral a, HEXADECIMALNoZero d) => Prism' a d Source #

>>> 15 ^? integralHEXADECIMALNoZero :: Maybe HEXDigit
Just HEXDigitF
>>> integralHEXADECIMALNoZero # HEXDigitF :: Integer
15

integralHEXADECIMAL :: (Integral a, HEXADECIMAL d) => Prism' a d Source #

>>> 15 ^? integralHEXADECIMAL :: Maybe HEXDigit
Just HEXDigitF
>>> integralHEXADECIMAL # HEXDigitF :: Integer
15

integralHEXDigits :: Integral a => a -> Either (NonEmpty HEXDigit) (NonEmpty HEXDigit) Source #

>>> integralHEXDigits (256 :: Int)
Right (HEXDigit1 :| [HEXDigit0, HEXDigit0])
>>> integralHEXDigits (0 :: Int)
Right (HEXDigit0 :| [])
>>> integralHEXDigits (-1 :: Int)
Left (HEXDigit0 :| [])
>>> integralHEXDigits (-256 :: Int)
Left (HEXDigitF :| [HEXDigitF])

_HEXDigitsIntegral :: Integral a => Either (NonEmpty HEXDigit) (NonEmpty HEXDigit) -> a Source #

>>> HEXDigitsIntegral (Right (HEXDigit1 :| [HEXDigit0, HEXDigit0])) :: Int
256
>>> HEXDigitsIntegral (Right (HEXDigit0 :| [])) :: Int
0
>>> HEXDigitsIntegral (Left (HEXDigit0 :| [])) :: Int
-1
>>> HEXDigitsIntegral (Left (HEXDigitF :| [HEXDigitF])) :: Int
-256

HeXaDeCiMaL

integralHeXaDeCiMaLNoZero :: (Integral a, HeXaDeCiMaLNoZero d) => Review a d Source #

>>> 15 ^? integralHeXaDeCiMaLNoZero :: Maybe HeXDigit
Just HeXDigitF
>>> integralHeXaDeCiMaLNoZero # HeXDigitF :: Integer
15

integralHeXaDeCiMaL :: (Integral a, HeXaDeCiMaL d) => Review a d Source #

>>> 15 ^? integralHeXaDeCiMaL :: Maybe HeXDigit
Just HeXDigitF
>>> integralHeXaDeCiMaL # HeXDigitF :: Integer
15

_HeXDigitsIntegral :: Integral a => Either (NonEmpty HeXDigit) (NonEmpty HeXDigit) -> a Source #

>>> HeXDigitsIntegral (Right (HeXDigit1 :| [HeXDigit0, HeXDigit0])) :: Int
256
>>> HeXDigitsIntegral (Right (HeXDigit0 :| [])) :: Int
0
>>> HeXDigitsIntegral (Left (HeXDigit0 :| [])) :: Int
-1
>>> HeXDigitsIntegral (Left (HeXDigitF :| [HeXDigitF])) :: Int
-256