# 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](https://package.elm-lang.org/packages/opvasger/comparable/latest/Comparable-Dict#equals)
&
[Set.equals](https://package.elm-lang.org/packages/opvasger/comparable/latest/Comparable-Dict#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.

```elm
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](https://package.elm-lang.org/packages/elm/core/latest).
