Chadtech/unique-list/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

List.Unique

A type to arrange things an order

UniqueList

type UniqueList a

An arrangement of things in an order. An UniqueList is kind of like a List, except there cant be duplicate elements. And, its kind of like a Set, except an UniqueLists elements go from first to last.

Basics

empty : UniqueList a

Create an empty `UniqueList

List.Unique.empty == List.Unique.fromList []
isEmpty : UniqueList a -> Bool

Check if an Order is empty

Order.isEmpty Order.empty == True
fromList : List a -> UniqueList a

Create a UniqueList from a List

toList : UniqueList a -> List a

Turn a UniqueList into a List

let
    u = [ 'u' ]


    doubleU = [ 'u', 'u' ]
in
    u == (List.Unique.toList <| List.Unique.fromList doubleU)
length : UniqueList a -> Int

Get the length of a UniqueList

nobleGases = List.Unique.fromList
    [ helium
    , neon
    , argon
    , krypton
    , xenon
    , radon
    ]


List.Unique.length nobleGases == 6
reverse : UniqueList a -> UniqueList a

Reverse a UniqueList

bestCoffeeDrinks ==
    List.Unique.fromList
        [ cortado
        , latte
        , coldbrew
        , coffee
        , mocha
        ]


worstCoffeeDrinks : UniqueList Coffee
worstCoffeeDrinks =
    List.Unique.reverse bestCoffeeDrinks
member : a -> UniqueList a -> Bool

Check if something is in a UniqueList

List.Unique.member "Grover Cleveland" usPresidents == True

Modifying UniqueLists

remove : a -> UniqueList a -> UniqueList a

Remove an element from a `UniqueList

addFirst : a -> UniqueList a -> UniqueList a

Add an element to a UniqueList, making it the first one

addBefore : a -> a -> UniqueList a -> UniqueList a

Add an element to a UniqueList before another element

addBefore `c` `b` (List.Unique.fromList [ `a`, `c`, `d` ])
    == List.Unique.fromList [ `a`, `b`, `c`, `d` ]
addAfter : a -> a -> UniqueList a -> UniqueList a

Add an element to a UniqueList before another element

addAfter `b` `c` (List.Unique.fromList [ `a`, `b`, `d` ])
    == List.Unique.fromList [ `a`, `b`, `c`, `d` ]
isBefore : a -> a -> UniqueList a -> Maybe Bool

Check if an element is before another, if it is in the UniqueList at all.

germanStates = List.Unique.fromList [ "Bavaria", "Brandenberg" ]


("Bavaria" |> List.Unique.isBefore "Brandenberg") germanStates == Just True


("Bavaria" |> List.Unique.isBefore "New York City") germanStates == Nothing
isAfter : a -> a -> UniqueList a -> Maybe Bool

Check if an element is after another, if it is in the UniqueList at all.