lue-bird/elm-typesafe-array/7.1.0

NOTE: the latest version is 34.0.1

Rerouted (retagged, needs approval). The tag now points at a different commit than when this version was published. The Lamdera package server serves a copy recovered from https://github.com/lue-bird/elm-typesafe-array.

What we checked: Tag 7.1.0 is still on github.com/lue-bird/elm-typesafe-array; its commit c17a96304817 is from 2021-05-03 17:31 UTC, after the version was published (2021-05-03 17:29 UTC); elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one and nothing else confirms its contents.

We could not verify this copy against what was published, so the Lamdera compiler asks before using it (y/n). Without a terminal, as in CI, it stops with an error unless approved:

  • lamdera make --auto-approve-package-rerouting approves rerouted versions for that run,
  • LAMDERA_AUTO_APPROVE_PACKAGE_REROUTING=1 does the same for every run in that environment,
  • LAMDERA_CACHE=off skips the Lamdera package server altogether: packages come from package.elm-lang.org and GitHub only, as with elm, and a rerouted version then fails to download.

Details · package.elm-lang.org's zip: https://github.com/lue-bird/elm-typesafe-array/zipball/7.1.0/

MinArr

If the maximum length is a type variable,

first :
    Arr (In (Nat1Plus orHigherMin) max) element
    -> element

use these operations instead of the ones in Arr or InArr

modify

element
-> Arr (In min max) element
-> Arr (Min (Nat1Plus min)) element

Put a new element after the others.

arrWithAtLeast5Elements
    |> MinArr.push "becomes the last"
--> : Arr (Min Nat6) String
Nat (ArgIn indexMin minLengthMinus1 indexMaybeExact)
-> LinearDirection
-> Arr (In (Nat1Plus minLengthMinus1) maxLength) element
-> Arr (In minLengthMinus1 maxLength) element

Kick out the element at an index in a direction.

removeLast arrWithAtLeast1Element =
    arrWithAtLeast1Element
        |> MinArr.removeAt nat0 LastToFirst
Nat (ArgIn indexMin minLengthMinus1 indexMaybeN)
-> LinearDirection
-> element
-> Arr (In (Nat1Plus minLengthMinus1) maxLength) element
-> Arr (Min (Nat2Plus minLengthMinus1)) element

Put a new element at an index in a direction.

arrWithAtLeast5Elements
    |> MinArr.insertAt nat0 FirstToLast
        "becomes the first"
--> : Arr (Min Nat6) String
Arr (In extensionMin extensionMax) element
-> Nat (ArgN extensionMin (Is min To extendedMin) x)
-> Arr (In min max) element
-> Arr (Min extendedMin) element

Append an Arr (In ...).

Arr.from3 1 2 3
    |> MinArr.extend nat3 arrWithAtLeast3Elements
--> : Arr (Min Nat6) ...
Nat (ArgN dropped (Is minTaken To min) x)
-> LinearDirection
-> Arr (In min max) element
-> Arr (In minTaken max) element

Elements after a certain number of elements from one side.

withAtLeast6Elements
    |> Arr.drop nat2 LastToFirst
--> : Arr (Min Nat4) ...

scan length

Nat
(ArgN
(Nat1Plus triedMinus1)
(Is a To (Nat1Plus triedMinus1PlusA))
x
)
-> { min : Nat (ArgN min (Is minToTriedMinus1 To triedMinus1) y) }
-> { equal : Arr (Only (Nat1Plus triedMinus1)) element -> result
, greater : Arr (Min (Nat2Plus triedMinus1)) element -> result
, less : Arr (In min triedMinus1PlusA) element -> result
}
-> Arr (In min max) element
-> result

Compare the length to an exact Nat (ArgN ...). Is it greater, less or equal?

min ensures that the Nat (ArgN ...) is bigger than the minimum length.

convertUserArguments :
    String
    -> Result String (Arr (Only Nat3))
convertUserArguments =
    String.words
        >> Array.fromList
        >> Arr.fromArray
        >> MinArr.isLength nat3
            { min = nat0 }
            { equal = Ok
            , less =
                \less ->
                    Err
                        ("I need 3 arguments, but there are only "
                            ++ String.fromInt (val (Arr.length less))
                            ++ "."
                        )
            , greater =
                \more ->
                    Err
                        ("I need exact 3 arguments, so "
                            ++ String.fromInt (val (Arr.length more))
                            ++ " is too much."
                        )
            }
Nat
(ArgN lowerBound (Is a To (Nat1Plus lowerBoundMinus1PlusA)) x)
-> { min : Nat (ArgN min (Is minToTriedMin To lowerBound) y) }
-> { equalOrGreater : Arr (Min lowerBound) element -> result
, less : Arr (In min lowerBoundMinus1PlusA) element -> result
}
-> Arr (In min max) element
-> result

Compare the length to an exact Nat (ArgN ...). Is it equalOrGreater or less?

min ensures that the lower bound is bigger than the minimum length.

convertUserArguments :
    String
    -> Result String (Arr (Min Nat3))
convertUserArguments =
    String.words
        >> Array.fromList
        >> Arr.fromArray
        >> MinArr.isLengthAtLeast nat3
            { min = nat0 }
            { equalOrGreater = Ok
            , less =
                \less ->
                    Err
                        ("I need at least 3 arguments, but there are only "
                            ++ String.fromInt (val (Arr.length less))
                            ++ "."
                        )
            }
Nat (ArgN upperBound (Is a To upperBoundPlusA) x)
-> { min : Nat (ArgN min (Is minToAtMostMin To upperBound) y) }
-> { equalOrLess : Arr (In min upperBoundPlusA) element -> result
, greater : Arr (Min (Nat1Plus upperBound)) element -> result
}
-> Arr (In min max) element
-> result

Is the length

  • equalOrLess than an upper bound or

  • greater?

min ensures that the upper bound is greater than the minimum length.

-- only up to 50 tags
tag : Arr (In min Nat50) String -> a -> Tagged a


tagIfValidTags : Array String -> a -> Maybe (Tagged a)
tagIfValidTags array value =
    array
        |> Arr.fromArray
        |> MinArr.isLengthAtMost nat50
            { equalOrLess = tag value >> Just
            , greater = \_ -> Nothing
            }

drop information

value : Arr (In min max) element -> Arr (Min min) element

Convert an exact Arr (In min ...) to a Nat (Min min).

between4And10Elements |> MinArr.value
--> : Arr (Min Nat4) ...

There is only 1 situation you should use this.

To make these the same type.

[ atLeast1Element, between1And10Elements ]

Elm complains:

But all the previous elements in the list are Arr (Min Nat1) ...

[ atLeast1Element
, between1And10Elements |> MinArr.value
]

extra

Nat
(ArgN lowerBound (Is a To (Nat1Plus lowerBoundMinus1PlusA)) x)
-> Codec String element
-> Codec String (Arr (Min lowerBound) element)

A Codec to serialize Arrs with a minimum amount of elements.

import Serialize




-- we can't start if we have no worlds to choose from!
serializeSaves :
    Serialize.Codec
        String
        (Arr (Min Nat1) World)
serializeSaves =
    MinArr.serialize nat1 serializeWorld


encode : Arr (In (Nat1Plus minMinus1) max) World -> Bytes
encode =
    MinArr.value
        >> Serialize.encodeToBytes serializeSaves


decode :
    Bytes
    ->
        Result
            (Serialize.Error String)
            (Arr (Min Nat1) World)
decode =
    Serialize.decodeFromBytes serializeSaves