If the maximum length is set to a specific value (also in ArgOnly),
-- only up to 50 tags
tag : Arr (In min Nat50) String -> a -> Tagged ause these operations instead of the ones in Arr or MinArr.
Append the elements of another Arr (In ...).
Append the elements of an Arr (Only ...).
Kick an element out of an Arr at a given index in a direction.
Use MinArr.push, if the max isn't known to be a certain value.
Elements after a certain number of elements from one side.
with6To10Elements
|> Arr.drop nat2 LastToFirst
--> : Arr (In Nat4 (Nat10Plus a)) ...Compared to a range from a lower to an upper bound, is the length BelowOrInOrAboveRange?
min ensures that the lower bound is greater than the minimum length.
chooseFormation :
Arr (In min Nat50) Character
-> Formation
chooseFormation characters =
case
(characters |> Arr.lowerMinLength nat0)
|> InArr.isLengthInRange nat10 nat20 { min = nat0 }
of
InRange between10And20 ->
SpecialAttack between10And20
BelowRange atMost9 ->
Retreat atMost9
AboveRange atLeast21 ->
Fight atLeast21Compare the length to an exact Nat (ArgN ...) length. Is it LessOrEqualOrGreater?
min ensures that the Nat (ArgN ...) is greater than the minimum length.
chooseFormation :
Arr (In min Nat50) Character
-> Formation
chooseFormation characters =
case
(characters |> Arr.lowerMinLength nat0)
|> InArr.isLength nat7 { min = nat0 }
of
Equal only7 ->
SpecialAttack only7
Less atMost6 ->
Retreat atMost6
Greater atLeast8 ->
Fight atLeast8Is the length BelowOrAtLeast as big as a Nat?
min ensures that the Nat is greater than the minimum length.
first5 :
Arr (In min max) element
-> Maybe (Arr (In Nat5 max) element)
first5 arr =
case
(arr |> Arr.lowerMinLength nat0)
|> MinArr.isLengthAtLeast nat5 { min = nat0 }
of
Below _ ->
Nothing
EqualOrGreater atLeast5 ->
Just atLeast5Is the length AtMostOrAbove a Nat?
min ensures that the Nat is greater than the minimum length.
-- at least 3 and only up to 50 tags
tag :
Arr (In (Nat3Plus orHigherMin) Nat50) String
-> a
-> Tagged a
tagIfValidTags :
Arr (In (Nat3Plus orHigherMin) max)
-> a
-> Maybe (Tagged a)
tagIfValidTags array value =
case
array
|> Arr.fromArray
|> InArr.isLengthAtMost nat50
of
Nat.EqualOrLess atMost53 ->
tag value atMost53 |> Just
Nat.Above _ ->
NothingA Codec to serialize Arrs within a minimum & maximum length.
import Serialize
serialize10To15Ints :
Serialize.Codec
String
(Arr (In Nat10 (Nat15Plus a)) Int)
serialize10To15Ints =
InArr.serialize Serialize.int nat10 nat15
encode :
Arr (In (Nat10Plus orHigherMin) Nat15) Int
-> Bytes
encode =
InNat.value
>> Serialize.encodeToBytes serialize10To15Ints
decode :
Bytes
->
Result
(Serialize.Error String)
(Arr (In Nat10 (Nat15Plus a) Int))
decode =
Serialize.decodeFromBytes serialize10To15IntsFor decoded Arrs with a length outside of the expected bounds, the Result is an error message.
Put a new element after the others.