If the maximum length is set to a specific value (also for Only),
-- only up to 50 tags
tag : Arr (In min_ Nat50) String -> a -> Tagged ause these operations instead of the ones in Arr or MinArr.
Kick an element out of the Arr at a given index in a direction.
removeLast arrWith1To10Elements =
arrWith1To10Elements
|> InArr.removeAt nat0 LastToFirstPut an element in the Arr at a given index in a direction.
Arr.from3 'a' 'c' 'd'
|> InArr.insertAt nat1 FirstToLast 'b'
--> Arr.from4 'a' 'b' 'c' 'd'
Arr.from3 'a' 'c' 'd'
|> Array.insertAt nat2 LastToFirst 'b'
--> Array.from4 'a' 'b' 'c' 'd'Attach elements of an Arr with an exact amount of elements to the right.
Arr.from3 1 2 3
|> InArr.append nat3 (Arr.from3 4 5 6)
--> Arr.from6 1 2 3 4 5 6Attach elements of an Arr which has multiple possible amounts to the right.
Arr.from3 1 2 3
|> InArr.appendIn nat3 nat5
arrWith3To5Elements
--> : Arr (In Nat6 (Nat8Plus a))Use append if the appended Arr has an exact amount of elements.
Add elements of an Arr with an exact amount of elements to the left.
Arr.from3 1 2 3
|> InArr.prepend nat3 (Arr.from3 4 5 6)
--> Arr.from6 4 5 6 1 2 3Add elements of an Arr which has multiple possible amounts to the left.
Arr.from3 1 2 3
|> InArr.prependIn nat3 nat5
arrWith3To5Elements
--> : Arr (In Nat6 (Nat8Plus a))Use prepend if the appended Arr has an exact amount of elements.
Elements after a certain number of elements in a direction.
Arr.from4 0 1 2 3
|> InArr.drop nat2 LastToFirst
--> Arr.from2 0 1
between6And10Elements
|> InArr.drop nat2 FirstToLast
--> : Arr (In Nat4 (Nat10Plus a_)) ...Compared to a range from a lower to an upper bound, is its length BelowOrInOrAboveRange?
lowest can be a number <= the minimum length.
chooseFormation :
Arr (In min Nat50) Character
-> Formation
chooseFormation characters =
case
characters
|> InArr.isLengthInRange nat10 nat20 { lowest = nat0 }
of
Nat.InRange between10And20 ->
SpecialAttack between10And20
Nat.BelowRange atMost9 ->
Retreat atMost9
Nat.AboveRange atLeast21 ->
Fight atLeast21Compare its length to a given exact length. Is it LessOrEqualOrGreater?
lowest can be a number <= the minimum length.
chooseFormation :
Arr (In min Nat50) Character
-> Formation
chooseFormation characters =
case
characters
|> InArr.isLength nat7 { lowest = nat0 }
of
Nat.Equal only7 ->
SpecialAttack only7
Nat.Less atMost6 ->
Retreat atMost6
Nat.Greater atLeast8 ->
Fight atLeast8Is its length BelowOrAtLeast as big as a Nat?
lowest can be a number <= the minimum length.
first5 :
Arr (In min max) element
-> Maybe (Arr (In Nat5 max) element)
first5 arr =
case
arr |> MinArr.isLengthAtLeast nat5 { lowest = nat0 }
of
Nat.Below _ ->
Nothing
Nat.EqualOrGreater atLeast5 ->
Just atLeast5Is its length AtMostOrAbove a given length?
lowest can be a number <= 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 { lowest = nat0 }
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 =
Arr.lowerMinLength nat10
>> 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.