rtfeldman/elm-sorter-experiment/2.1.0

NOTE: the latest version is 2.1.2

Rerouted (retagged, verified). The tag now points at a different commit than when this version was published. The Lamdera package server serves a copy recovered from https://github.com/rtfeldman/elm-sorter-experiment.

What we checked: Tag 2.1.0 now points at 76d3ee545ee4, not the published commit. Rebuilt with git archive from commit 70c636c297ef of https://github.com/rtfeldman/elm-sorter-experiment (zip prefix rtfeldman-elm-sorter-experiment-70c636c/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 a6ae57db2a43d6f13840e5b912bf0b70134eeb7b.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/rtfeldman/elm-sorter-experiment/zipball/2.1.0/

Sort.Set

A set of unique values.

Insert, remove, and query operations all take O(log n) time.

This implementation is based on Skinney/elm-dict-exploration, except that it uses Sorter instead of comparable, so it permits keys that are not comparable.

Sets

type Set t

Represents a set of unique values. So (Set Int) is a set of integers and (Set String) is a set of strings.

Build

empty : Sorter a -> Set a

Create an empty set.

singleton : Sorter a -> a -> Set a

Create a set with one value.

insert : a -> Set a -> Set a

Insert a value into a set.

remove : a -> Set a -> Set a

Remove a value from a set. If the value is not found, no changes are made.

Query

isEmpty : Set a -> Bool

Determine if a set is empty.

memberOf : Set a -> a -> Bool

Return True if the given value is in the given set.

size : Set a -> Int

Return the number of elements in a set.

eq : Set a -> Set a -> Bool

Check if two sets are equal

Combine

union : Sorter a -> Set a -> Set a -> Set a

Get the union of two sets. Keep all values.

Lists

toList : Set a -> List a

Convert a set into a list, sorted from lowest to highest.

fromList : Sorter a -> List a -> Set a

Convert a list into a set, removing any duplicates.

Transform

map : Sorter b -> (a -> b) -> Set a -> Set b

Map a function onto a set, creating a new set with no duplicates.

keepIf : (a -> Bool) -> Set a -> Set a

Only keep elements that pass the given test.

numbers =
    Set.fromList [ -2, -1, 0, 1, 2, 3, 4, 5 ]


positives =
    Set.keepIf (\num -> num > 0) numbers


evens =
    Set.keepIf (\num -> num % 2 == 0) numbers


positiveEvens =
    -- Intersection
    Set.keepIf (Set.member evens) positives
dropIf : (a -> Bool) -> Set a -> Set a

Remove elements that pass the given test.

numbers =
    Set.fromList [ -2, -1, 0, 1, 2, 3, 4, 5 ]


positives =
    Set.dropIf (\num -> num <= 0) numbers


evens =
    Set.dropIf (\num -> num % 2 == 1) numbers


positiveOdds =
    -- Difference
    Set.dropIf (Set.member evens) positives
foldl : (a -> b -> b) -> b -> Set a -> b

Fold over the values in a set, in order from lowest to highest.

foldr : (a -> b -> b) -> b -> Set a -> b

Fold over the values in a set, in order from highest to lowest.

partition : (a -> Bool) -> Set a -> ( Set a, Set a )

Create two new sets. The first contains all the elements that passed the given test, and the second contains all the elements that did not.