carlsson87/mod11/1.0.0

NOTE: the latest version is 1.0.1

Mod11

Problems

type Error
= NumbersOutOfRange
| EmptySequence
| InvalidMod11Number

The Modulus 11 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 11 algorithm.

hasValidCheckDigit [3, 2, 4, 5, 5, 8] == Ok True


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


hasValidCheckDigit [] == Err EmptySequence


hasValidCheckDigit [0, 0, 0] = Err InvalidMod11Number

Constructing

calculateCheckDigit : List Int -> Result Error Int

Calculate the "check digit" for a given sequence of digits.

calculateCheckDigit [ 1, 2, 3 ] == Ok 6


calculateCheckDigit [ 1, 2, 30 ] == Err NumbersOutOfRange