If the maximum length is set to a specific value (also in ArgOnly),
-- only up to 50 tags
tag :
Arr (In min Nat50 maybeN) 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.
Compared to a range from a lower to an upper bound, is the length
inRange
greater than the upper bound or
less than the lower bound?
min ensures that the lower bound is greater than the minimum length.
chooseFormation :
Arr (In Nat0 Nat50) Character
-> Formation
chooseFormation characters =
characters
|> InArr.isLengthInRange nat10
nat20
{ min = nat0 }
{ equal = SpecialAttack
, less = Retreat
, more = Fight
}
type Formation
= SpecialAttack (Arr (In Nat10 Nat20) Character)
| Retreat (Arr (In Nat0 Nat9) Character)
| Fight (Arr (In Nat21 Nat50) Character)Compare the length to an exact Nat (ArgN ...) length.
Are there more, less or an equal amount of elements?
min ensures that the Nat (ArgN ...) is greater than the minimum length.
chooseFormation :
Arr (In Nat0 Nat50) Character
-> Formation
chooseFormation characters =
characters
|> InArr.isLength nat7
{ min = nat0 }
{ equal = SpecialAttack
, less = Retreat
, more = Fight
}
type Formation
= SpecialAttack (Arr (Only Nat7) Character)
| Retreat (Arr (In Nat0 Nat6) Character)
| Fight (Arr (In Nat8 Nat50) Character)Is the length
equalOrGreater than a lower bound or
less?
min ensures that the lower bound is greater than the minimum length.
first5 :
Arr (In min max maybeN) element
-> Maybe (Arr (In Nat5 max maybeN) element)
first5 =
MinArr.lowerMinLength nat0
>> MinArr.isLengthAtLeast nat5
{ min = nat0 }
{ less = \_ -> Nothing
, equalOrGreater = Just
}Is the length
equalOrLess than a upper bound or
greater?
min ensures that the upper bound is greater than the minimum length.
-- at least 3 and only up to 50 tags
tag :
Arr (In (Nat3Plus orHigherMin) Nat50 maybeN) String
-> a
-> Tagged a
tagIfValidTags :
Arr (In (Nat3Plus orHigherMin) max maybeN)
-> a
-> Maybe (Tagged a)
tagIfValidTags array value =
array
|> Arr.fromArray
|> InArr.isLengthAtMost nat50
{ equalOrLess = tag value >> Just
, greater = \_ -> Nothing
}A 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 maybeN) 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.