version | 1.0.0 |
license | BSD-3-Clause |
native-modules | False |
elm-version | 0.18.0 <= v < 0.19.0 |
Tag | 1.0.0 |
Committed At | 2018-06-29 08:15:18 UTC |
elm-lang/core | 5.0.0 <= v < 6.0.0 | 5.1.1 |
It's right there in the name, but just to be totally clear about it:
⚠️ THIS IS AN EXPERIMENT! ⚠️
I have a hypothesis that these may be good ideas, but they may not be! The purpose of this package is to facilitate trying them out and learning more.
This package is a group of related experiments I've been pondering for awhile. They are:
Sorter
API that replaces List.sort
, List.sortBy
, and List.sortWith
with a single function (Sort.list
). In particular, Sort.by
and Sort.reverse
(when used together) nicely scratch an itch I've encountered on a few different occasions.Dict
and Set
that use Sorter
to permit keys that are not comparable
.Dict
and Set
(explained below).Since we're already in experimental territory, I based this experiment on another
one; this is using Skinney/elm-dict-exploration
under the hood for some performance benefits.
Dict
and Set
modules, by Evan Czaplickieeue56/elm-all-dict
by Noah Hallrobertjlooby/elm-generic-dict
by Robert J. LoobySkinney/elm-dict-exploration
by Robin Heggelund HansenSet
and Dict
API ChangesIn this package, the following operations on both Set
and Dict
now take
a Sorter
as their first argument:
empty
singleton
fromList
merge
Additionally, diff
has been given named arguments in order to prevent ordering mistakes. It is now:
{-| Keep a value when it appears in the `original` set
but not in the `other` set. The `original` set's `Sorter` will be used.
-}
diff : { original : Set a, other : Set a } -> Set a
Set
API Changesinsert
-insert : a -> Set a -> Set a
+add : a -> Set a -> Set a
There is strong consensus among languages for what this operation should be called.
Python, Ruby, Java, JavaScript, and OCaml, all call this add
. Erlang calls it
addElement
and Scala overloads (+)
for this operation.
Only Haskell calls it insert
.
map
-map : (a -> b) -> Set a -> Set b
+map : Sorter b -> (a -> b) -> Set a -> Set b
An extra argument is needed to specify the Sorter
for the resulting Set
.
intersect
and union
-intersect : Set a -> Set a -> Set a
+intersect : Sorter a -> Set a -> Set a
-union : Set a -> Set a -> Set a
+union : Sorter a -> Set a -> Set a
These now take an explicit Sorter
in order to make it clear which sorting
operation will be used.
Dict
API Changesinsert
-insert : k -> v -> Dict k v -> Dict k v
+store : k -> v -> Dict k v -> Dict k v
There is no consensus among languages for what this operation should be called.
Ruby's store
seems clearer than Haskell's insert
because "inserting" is
often an operation that strictly increases the size of the collection
(e.g. INSERT
in SQL) whereas "storing" is idempotent.
(Other alternatives considered: put
from Java, add
from OCaml, replace
from ReasonML, set
from JavaScript.)
intersect
-intersect : Dict k v -> Dict k v -> Dict k v
+intersect : { preferred : Dict k v, other : Dict k v } -> Dict k v
intersect
has been given named arguments in order to clarify which values will be kept.
union
-union : Dict k v -> Dict -> k v -> Dict k v
+storeAll : { from : Dict k v, into : Dict k v } -> Dict k v
union
has been renamed and given named arguments to make it clearer what happens
in the event of collisions.
"It takes all the key/value pairs from one dictionary and store
s them into
the other one" builds on the caller's understanding of how store
resolves
collisions.
This API also makes it clear which dictionary's Sorter
will be used.