Is the Nat BelowOrAtLeast a given number?
factorial : Nat (ArgIn min max ifN_) -> Nat (Min Nat1)
factorial =
factorialBody
factorialBody : -- as in factorial
factorialBody =
case x |> MinNat.isAtLeast nat1 { lowest = nat0 } of
Nat.Below _ ->
MinNat.value nat1
Nat.EqualOrGreater atLeast1 ->
Nat.mul atLeast1
(factorial
(atLeast1 |> MinNat.sub nat1)
)Is the Nat AtMostOrAbove a given number?
goToU18Party : { age : Nat (ArgIn min Nat17 ifN_) } -> Snack
tryToGoToU18Party { age } =
case age |> MinNat.isAtMost nat17 { lowest = nat0 } of
EqualOrLess age ->
Just (goToU18Party { age = age })
Greater _ ->
NothingSubtract an exact Nat (N ...).
atLeast7 |> MinNat.sub nat2
--> : Nat (Min Nat5)Add a fixed Nat (N ...) value.
atLeast70 |> InNat.add nat7
--> : Nat (Min Nat77)Subtract a Nat (In ...). The second argument is the maximum of the subtracted Nat.
atLeast6 |> MinNat.subMax nat5 between0And5
--> : Nat (Min Nat1)Add a Nat (In ...). The second argument is the minimum added value.
atLeast5 |> MinNat.addMin nat2 atLeast2
--> : Nat (Min Nat7)Convert a Nat (ArgIn min ...) to a Nat (Min min).
between3And10 |> MinNat.value
--> : Nat (Min Nat4)There is only 1 situation you should use this.
To make these the same type.
[ atLeast1, between1And10 ]Elm complains:
But all the previous elements in the list are:
Nat (Min Nat1)
[ atLeast1
, between1And10 |> MinNat.value
]A Codec to serialize Nats with a lower bound.
import Serialize
serializeNaturalNumber :
Serialize.Codec
String
(Nat (Min Nat0))
serializeNaturalNumber =
MinNat.serialize nat0
encode : Nat (ArgIn min max ifN_) -> Bytes
encode =
MinNat.value
>> Serialize.encodeToBytes serializeNaturalNumber
decode :
Bytes
-> Result (Serialize.Error String) (Nat (Min Nat0))
decode =
Serialize.decodeFromBytes serializeNaturalNumber
Is the
NatLessOrEqualOrGreaterthan a given number?lowestcan be a number <= the minimum.