indique/elm-bounded-nat/7.0.0

NOTE: the latest version is 13.0.0

Nat

type alias Nat range =
Nat range

A bounded natural number (>= 0).

-- >= 4
Nat (Min Nat4)


-- 2 <= nat <= 12
Nat (In Nat2 Nat12)


-- = 3
Nat (Only Nat3)


-- = 3, & 3, described as a difference
Nat (N Nat3 Is (Difference a To (Nat3Plus a)))


-- either one of the above
Nat range


-- Not constuctable
Nat Banana

transform

toInt : Nat range -> Int

Convert a Nat to an Int.

nat4 |> Nat.toInt --> 4
nat4 |> Nat.N.toIn |> Nat.toInt --> 4
nat4 |> Nat.N.toMin |> Nat.toInt --> 4


compare : Nat range -> Nat range -> Order
compare a b =
    compare (Nat.toInt a) (Nat.toInt b)
bi : (Int -> Int -> result) -> Nat aRange -> Nat bRange -> result

Use the Int values of two Nats to return a result.

Nat.bi (>=) nat5 nat4 --> True


Nat.bi (>=) nat5 nat40 --> False

Note, that you must give the Nats in the same order you would give Ints.

Don't overuse this.

compare

theGreater : Nat range -> Nat range -> Nat range

The greater of 2 Nats. Works just like Basics.max.

Nat.theGreater
    (nat3 |> Nat.N.toMin)
    (nat4 |> Nat.N.toMin |> Nat.Min.lowerMin (nat3 |> Nat.N.toIn))
--> Nat 4
theSmaller : Nat range -> Nat range -> Nat range

The smaller of 2 Nats. Works just like Basics.min.

Nat.theSmaller
    (nat3 |> Nat.N.toMin)
    (nat4 |> Nat.N.toMin |> Nat.Min.lowerMin (nat3 |> Nat.N.toIn))
--> Nat 3