The absolute value of an Int, which is at least Nat0.
MinNat.abs 16 --> Nat 16
MinNat.abs -4 --> Nat 4Really only use this if you want the absolute value.
badLength list =
List.length >> MinNat.abs
goodLength =
List.foldl
(\_ ->
MinNat.addN nat1
>> InNat.lowerMin nat0
)
(nat0 |> NNat.toMin)If something like this isn't possible, use MinNat.intAtLeast!
Nat (In ...)s from a first to a last value.
from3To10 : List (Nat (ValueIn Nat3 (Nat10Plus a)))
from3To10 =
InNat.range nat3 nat10
from3ToAtLeast10 : List (Nat (ValueMin Nat3))
from3ToAtLeast10 =
InNat.range nat3 atLeast10The resulting List is never empty.
Generate a random Nat (In ...) in a range.
Convert a Nat to an Int.
nat4 |> Nat.toInt --> 4
nat4 |> NNat.toIn |> Nat.toInt --> 4
nat4 |> NNat.toMin |> Nat.toInt --> 4
compare : Nat range -> Nat range -> Order
compare a b =
compare (Nat.toInt a) (Nat.toInt b)Use the Int values of two Nats to return a result.
Nat.bi (>=) nat5 nat4 --> True
Nat.bi (>=) nat5 nat40 --> FalseNote, that you must give the Nats in the same order you would give Ints.
Don't overuse this.
The greater of 2 Nats. Works just like Basics.max.
Nat.theGreater atLeast3
(atLeast4 |> InNat.lowerMin nat3)
--> Nat 4The smaller of 2 Nats. Works just like Basics.min.
Nat.theSmaller atLeast3
(atLeast4 |> InNat.lowerMin nat3)
--> Nat 3An Int compared to a range from first to last.
rejectOrAcceptUserInt =
isIntInRange nat1 nat100
{ less = Err "must be >= 1"
, greater = \_-> Err "must be <= 100"
, inRange = Ok
}
rejectOrAcceptUserInt (NNat.toIn nat0)
--> Err "must be >= 1"If the Int >= a minimum, Just the Nat (Min minimum), else Nothing.
4 |> Nat.isIntAtLeast nat5 --> Nothing
1234 |> Nat.isIntAtLeast nat5 --> Just (Nat 1234)A Nat (Min ...) from an Int; if the Int < minimum, minimum is returned.
9 |> Nat.intAtLeast (nat3 |> NNat.toMin)
--> Nat 9
0 |> Nat.intAtLeast (nat3 |> NNat.toMin)
--> Nat 3You can also use this if you know an Int must be at least minimum.
But avoid it if you can do better, like
goodLength =
List.foldl
(\_ ->
MinNat.addN nat1
>> InNat.lowerMin nat0
)
(nat0 |> InNat.toMin)If you want to handle the case < minimum yourself, use Nat.isIntAtLeast.
A Nat (In ...) from an Int, clamped between a minimum & maximum.
Int < minimum, minimum is returnedInt > maximum, maximum is returnedclampBetween3And12 =
Nat.intInRange nat3 nat12
9 |> clampBetween3And12 --> Nat 9
0 |> clampBetween3And12 --> Nat 3
99 |> clampBetween3And12 --> Nat 12If you want to handle the cases < minimum & > maximum explicitly, use isIntInRange.
A bounded natural number (
>= 0).value / return types
function argument types