Orasund/elm-static-array/1.0.1

NOTE: the latest version is 3.0.0

StaticArray.Index

This module contains the Index type which can be though of as a range type. A value of type Index n is in between 0 and n.

This type will be replaced in compile type with an Int. Resulting in no performance loss.

type alias Index n =
Index n

An Index is integer between 0 and n-1

range : Length n -> List (Index n)

Returns the list of all indexes of an array with length n

first : Index n

The first index of an array

last : Length n -> Index n

The last element of an array with length n

fromModBy : Length n -> Int -> Index n

Construct an Index by wrapping higher values

import StaticArray.Length as Length


fromModBy (Length.one |> Length.plus2) 3
--> first --0
fromLessThen : Length n -> Int -> Index n

Construct an Index by cutting off higher values

import StaticArray.Length as Length exposing (Length)
import StaticArray.Index exposing (OnePlus,Two)


length : Length (OnePlus Two)
length =
    (Length.one |> Length.plus2)


fromLessThen length 3
--> last length --2
increase : Length n -> Index n -> Maybe (Index n)

Increases the index by one. You can not increase the last index.

decrease : Index n -> Maybe (Index n)

Increases the index by one. You can not decrease the first index.

toInt : Index n -> Int

Convert to Integer. You can convert it back by using either fromModBy or fromLessThen

setLength : Length m -> Index n -> Maybe (Index m)

Change the range of the index. If the length is smaller then the index, it returns Nothing.

type One
= One
type alias Two =
type alias Three =
OnePlus Two
type alias Four =
OnePlus Three
type alias Five =
OnePlus Four
type alias Seven =
OnePlus Six
type alias Eight =
OnePlus Seven
type alias Nine =
OnePlus Eight
type alias Ten =
OnePlus Nine
type alias Twenty =
TenPlus Ten
type OnePlus a
= OnePlus a
type alias TwoPlus a =
type alias FourPlus a =
TwoPlus (TwoPlus a)
type alias FivePlus a =
OnePlus (FourPlus a)
type alias EightPlus a =
FourPlus (FourPlus a)
type alias TenPlus a =
FivePlus (FivePlus a)
type alias TwentyPlus a =
TenPlus (TenPlus a)