Orasund / elm-static-array / StaticArray.Length

This module introduces the Length type. The length type is an integer but its value is known in compile time. This way we can ensure that no index out of bounds error occurs.

Basics


type alias Length n =
StaticArray.Internal.Length n

A length represents the length of a static array

import StaticArray

StaticArray.singleton 42
    |> StaticArray.push 7
    |> StaticArray.length
    --> two

one : Length StaticArray.Index.One

Length of an array with one element

plus1 : Length n -> Length (StaticArray.Index.OnePlus n)

Increases the length by one

minus1 : Length (StaticArray.Index.OnePlus n) -> Length n

Decreases the length by one

toInt : Length n -> Basics.Int

Converts a length into int

four
    |> toInt
    --> 4

Constructors

two : Length StaticArray.Index.Two

Length of an array with two elements

three : Length StaticArray.Index.Three

Length of an array with three elements

four : Length StaticArray.Index.Four

Length of an array with four elements

five : Length StaticArray.Index.Five

Length of an array with five elements

six : Length StaticArray.Index.Six

Length of an array with six elements

seven : Length StaticArray.Index.Seven

Length of an array with seven elements

eight : Length StaticArray.Index.Eight

Length of an array with eight elements

nine : Length StaticArray.Index.Nine

Length of an array with nine elements

ten : Length StaticArray.Index.Ten

Length of an array with ten elements

twenty : Length StaticArray.Index.Twenty

Length of an array with twenty elements

Addition

plus2 : Length n -> Length (StaticArray.Index.TwoPlus n)

Increases the length by two

plus4 : Length n -> Length (StaticArray.Index.FourPlus n)

Increases the length by four

plus5 : Length n -> Length (StaticArray.Index.FivePlus n)

Increases the length by five

plus8 : Length n -> Length (StaticArray.Index.EightPlus n)

Increases the length by eight

plus10 : Length n -> Length (StaticArray.Index.TenPlus n)

Increases the length by ten

plus20 : Length n -> Length (StaticArray.Index.TwentyPlus n)

Increases the length by twenty

Subtraction

minus2 : Length (StaticArray.Index.TwoPlus n) -> Length n

Decreases the length by two

minus4 : Length (StaticArray.Index.FourPlus n) -> Length n

Decreases the length by four

minus5 : Length (StaticArray.Index.FivePlus n) -> Length n

Decreases the length by five

minus8 : Length (StaticArray.Index.EightPlus n) -> Length n

Decreases the length by eight

minus10 : Length (StaticArray.Index.TenPlus n) -> Length n

Decreases the length by ten

minus20 : Length (StaticArray.Index.TwentyPlus n) -> Length n

Decreases the length by twenty