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

Data.Digit.Natural

Synopsis

# Documentation

>>> _NaturalDigits # 0
0 :| []

>>> _NaturalDigits # 1
1 :| []

>>> _NaturalDigits # 9223372036854775807
9 :| [2,2,3,3,7,2,0,3,6,8,5,4,7,7,5,8,0,7]

>>> (9 :| [2,2,3,3,7,2,0,3,6,8,5,4,7,7,5,8,0,7]) ^? _NaturalDigits
Just 9223372036854775807

>>> (1 :| []) ^? _NaturalDigits
Just 1

\x -> digitsToNatural ( naturalToDigits x ) == Just x

NonEmpty Digits from a Natural number

>>> naturalDigits 0
0 :| []

>>> naturalDigits 9
9 :| []

>>> naturalDigits 393564
3 :| [9,3,5,6,4]

>>> naturalDigits 9223372036854775807
9 :| [2,2,3,3,7,2,0,3,6,8,5,4,7,7,5,8,0,7]


Create a number from a list of digits with the integer bounds of the machine.

>>> naturalFromDigits (D.x3 :| [D.x4])
Just 34

>>> naturalFromDigits (D.Digit3 :| [D.Digit9,D.Digit3,D.Digit5,D.Digit6,D.Digit4])
Just 393564

>>> naturalFromDigits (D.x0 :| [])
Just 0


Int maxBound for Int64 >>> naturalFromDigits (D.x9 :| [D.x2,D.x2,D.x3,D.x3,D.x7,D.x2,D.x0,D.x3,D.x6,D.x8,D.x5,D.x4,D.x7,D.x7,D.x5,D.x8,D.x0,D.x7]) Just 9223372036854775807

Int maxBound + 1 for Int64 >>> naturalFromDigits (D.x9 :| [D.x2,D.x2,D.x3,D.x3,D.x7,D.x2,D.x0,D.x3,D.x6,D.x8,D.x5,D.x4,D.x7,D.x7,D.x5,D.x8,D.x0,D.x8]) Nothing