IntThe 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 |> NNat.toIn)
)
(nat0 |> NNat.toMin)If something like this isn't possible, use MinNat.intAtLeast!
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
(nat3 |> NNat.toMin)
(nat4 |> NNat.toMin |> MinNat.lowerMin (nat3 |> NNat.toIn))
--> Nat 4The smaller of 2 Nats. Works just like Basics.min.
Nat.theSmaller
(nat3 |> NNat.toMin)
(nat4 |> NNat.toMin |> MinNat.lowerMin (nat3 |> NNat.toIn))
--> Nat 3An Int compared to a range from first to last.
rejectOrAcceptUserInt =
isIntInRange (nat1 |> NNat.toIn) (nat100 |> NNat.toIn)
{ 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 |> NNat.toIn) --> Nothing
1234 |> Nat.isIntAtLeast (nat5 |> NNat.toIn) --> 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 |> NNat.toIn)
)
(nat0 |> NNat.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 |> NNat.toIn) (nat12 |> NNat.toIn)
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).