carlsson87/mod10/2.0.0

Mod10

Problems

type Error
= NumbersOutOfRange
| EmptySequence

The Modulus 10 algorithm works on sequences of digits, but since boths lists and integers can represent values that are invalid in this context there are some cases that will result in errors.

Validating

hasValidCheckDigit : List Int -> Result Error Bool

Check if the last digit in a sequence of digits is a valid check digit for the sequence according to the Modulus 10 algorithm.

hasValidCheckDigit [ 1, 2, 3 ] == Ok False


hasValidCheckDigit [ -2, 3 4 ] == Err NumbersOutOfRange


hasValidCheckDigit [] == Err EmptySequence

Constructing

calculateCheckDigit : List Int -> Result Error Int

calculateCheckDigit the check digit for a given sequence of digits.