opvasger/comparable/1.2.0

NOTE: the latest version is 2.0.0

Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/opvasger/comparable is gone (deleted or private); Software Heritage not asked yet (this run's --swh-calls were used up); no fork with tag 1.2.0 found (60 same-name repos checked); no cached copy. Use another version.

Details

Elm Comparable

This package contains replacements for functions in the core modules that rely on implicit comparison of values.

Implicit comparison relies on the convenient comparable type-variable which has special semantics. This is useful for numbers, characters, strings, lists of comparable things, and tuples of comparable things.

Use Dict.equals & Set.equals instead of [(==)](https://package.elm-lang.org/packages/elm/core/latest/Basics#(==)) to compare entries, as both have shifting internals that doesn't work as expected with structural equality.

module Example exposing (N, compare, oneAndTwo, sort, toInt)

import Comparable
import Comparable.Set as Set exposing (Set)

type N = One | Two | Three

-- sort of nice, no?
sort : List N -> List N
sort = Comparable.sort compare

-- dict/set are available too.
oneAndTwo : Set N
oneAndTwo = Set.fromList compare [One,Two,Two,Two,Two]

-- this one builds on Basics.compare, which is usually what you want.
compare : N -> N -> Order
compare a b = Basics.compare (toInt a) (toInt b)

-- these conversions are often implemented for other purposes too.
toInt : N -> Int
toInt n =
    case n of
        One ->   1
        Two ->   2
        Three -> 3

The core modules for Elm are documented here.