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.
StaticArray.Internal.Index n
An Index is integer between 0 and n-1
range : StaticArray.Internal.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 : StaticArray.Internal.Length n -> Index n
The last element of an array with length n
import StaticArray.Length as Length
import StaticArray.Index as Index
Length.five
|> last
|> Index.toInt
--> 4
fromModBy : StaticArray.Internal.Length n -> Basics.Int -> Index n
Construct an Index by wrapping higher values
import StaticArray.Length as Length
fromModBy (Length.one |> Length.plus2) 3
--> first --0
fromLessThen : StaticArray.Internal.Length n -> Basics.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 : StaticArray.Internal.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)
Decreases the index by one. You can not decrease the first index.
toInt : Index n -> Basics.Int
Convert to Integer. You can convert it back by using either fromModBy
or fromLessThen
fromInt : StaticArray.Internal.Length n -> Basics.Int -> Maybe (Index n)
Turn a number into an Index and returns Nothing if the number is not in the range.
import StaticArray.Length as Length
fromInt Length.one -1 --> Nothing
fromInt Length.one 0 --> Just (fromLessThen Length.one 0)
fromInt Length.one 1 --> Nothing
setLength : StaticArray.Internal.Length m -> Index n -> Maybe (Index m)
Change the range of the index. If the length is smaller then the index, return Nothing.
OnePlus One
OnePlus Two
OnePlus Three
OnePlus Four
OnePlus Five
OnePlus Six
OnePlus Seven
OnePlus Eight
OnePlus Nine
TenPlus Ten
OnePlus (OnePlus a)
TwoPlus (TwoPlus a)
OnePlus (FourPlus a)
FourPlus (FourPlus a)
FivePlus (FivePlus a)
TenPlus (TenPlus a)