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

Data.Digit.Integral

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 (4 :: Int)
Right (BinDigit1 :| [BinDigit0, BinDigit0])

>>> integralBinDigits (0 :: Int)
Right (BinDigit0 :| [])

>>> integralBinDigits (-1 :: Int)
Left (BinDigit0 :| [])

>>> integralBinDigits (-4 :: Int)
Left (BinDigit1 :| [BinDigit1])

>>> 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 (64 :: Int)
Right (OctDigit1 :| [OctDigit0, OctDigit0])

>>> integralOctDigits (0 :: Int)
Right (OctDigit0 :| [])

>>> integralOctDigits (-1 :: Int)
Left (OctDigit0 :| [])

>>> integralOctDigits (-64 :: Int)
Left (OctDigit7 :| [OctDigit7])

>>> 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 (100 :: Int)
Right (DecDigit1 :| [DecDigit0, DecDigit0])

>>> integralDecDigits (0 :: Int)
Right (DecDigit0 :| [])

>>> integralDecDigits (-1 :: Int)
Left (DecDigit0 :| [])

>>> integralDecDigits (-100 :: Int)
Left (DecDigit9 :| [DecDigit9])

>>> decDigitsIntegral (Right (DecDigit1 :| [DecDigit0, DecDigit0])) :: Int
100

>>> decDigitsIntegral (Right (DecDigit0 :| [])) :: Int
0

>>> decDigitsIntegral (Left (DecDigit0 :| [])) :: Int
-1

>>> decDigitsIntegral (Left (DecDigit9 :| [DecDigit9])) :: Int
-100


>>> 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 (256 :: Int)
Right (HexDigit1 :| [HexDigit0, HexDigit0])

>>> integralHexDigits (0 :: Int)
Right (HexDigit0 :| [])

>>> integralHexDigits (-1 :: Int)
Left (HexDigit0 :| [])

>>> integralHexDigits (-256 :: Int)
Left (HexDigitf :| [HexDigitf])

>>> hexDigitsIntegral (Right (HexDigit1 :| [HexDigit0, HexDigit0])) :: Int
256

>>> hexDigitsIntegral (Right (HexDigit0 :| [])) :: Int
0

>>> hexDigitsIntegral (Left (HexDigit0 :| [])) :: Int
-1

>>> hexDigitsIntegral (Left (HexDigitf :| [HexDigitf])) :: Int
-256


>>> 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 (256 :: Int)
Right (HEXDigit1 :| [HEXDigit0, HEXDigit0])

>>> integralHEXDigits (0 :: Int)
Right (HEXDigit0 :| [])

>>> integralHEXDigits (-1 :: Int)
Left (HEXDigit0 :| [])

>>> integralHEXDigits (-256 :: Int)
Left (HEXDigitF :| [HEXDigitF])

>>> HEXDigitsIntegral (Right (HEXDigit1 :| [HEXDigit0, HEXDigit0])) :: Int
256

>>> HEXDigitsIntegral (Right (HEXDigit0 :| [])) :: Int
0

>>> HEXDigitsIntegral (Left (HEXDigit0 :| [])) :: Int
-1

>>> HEXDigitsIntegral (Left (HEXDigitF :| [HEXDigitF])) :: Int
-256


>>> 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 (Right (HeXDigit1 :| [HeXDigit0, HeXDigit0])) :: Int
256

>>> HeXDigitsIntegral (Right (HeXDigit0 :| [])) :: Int
0

>>> HeXDigitsIntegral (Left (HeXDigit0 :| [])) :: Int
-1

>>> HeXDigitsIntegral (Left (HeXDigitF :| [HeXDigitF])) :: Int
-256