If the maximum length is set to a specific value (also in Only),
-- 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 a Arr (N ...).
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 (ValueIn Nat0 Nat50) Character
-> Formation
chooseFormation characters =
characters
|> InArr.isLengthInRange nat10
nat20
{ min = nat0 }
{ equal = SpecialAttack
, less = Retreat
, more = Fight
}
type Formation
= SpecialAttack (Arr (ValueIn Nat10 Nat20) Character)
| Retreat (Arr (ValueIn Nat0 Nat9) Character)
| Fight (Arr (ValueIn Nat21 Nat50) Character)Compare the length to an exact Nat (N ...) length.
Are there more, less or an equal amount of elements?
min ensures that the Nat (N ...) is greater than the minimum length.
chooseFormation :
Arr (ValueIn Nat0 Nat50) Character
-> Formation
chooseFormation characters =
characters
|> InArr.isLength nat7
{ min = nat0 }
{ equal = SpecialAttack
, less = Retreat
, more = Fight
}
type Formation
= SpecialAttack (Arr (ValueOnly Nat7) Character)
| Retreat (Arr (ValueIn Nat0 Nat6) Character)
| Fight (Arr (ValueIn 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
}Convert it to an Arr (ValueIn min max).
Arr.from3 1 2 3 |> InArr.value
--> : Nat (ValueIn Nat3 (Nat3Plus a))There is only 1 situation you should use this.
To make these the same type.
[ arrWith3To10Elements
, Arr.repeat nat3 0
]Elm complains:
But all the previous elements in the list are
Arr (ValueIn Nat3 Nat10) ...
[ arrWith3To10Elements
, Arr.repeat nat3 0 |> InArr.value
]A Codec to serialize Arrs within a minimum & maximum length.
import Serialize
serialize10To15Ints :
Serialize.Codec
String
(Arr (ValueIn 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 (ValueIn 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.