Multiple key Orderings
Configure what's considered a key inside a KeysSet
Create starting with Keys.for and building with |> Keys.by as shown in
the readme examples
You can just ignore the Typed thing but if you're curious → typed-value
By which aspect = key and in which key Order elements should be sorted
Ordering by the element itself.
Short for
Keys.identity order =
for identity |> by ( identity, Map.identity ) orderin KeysSet
import Map
import Order
import Int.Order
import N exposing (Up, To, N0)
import KeysSet
intIncreasing : Keys.Identity Int Int.Order.Increasing
intIncreasing =
Keys.identity Int.Order.increasing
KeysSet.fromList intIncreasing [ -1, 5, 5, 8, 7 ]
|> KeysSet.toList ( intIncreasing, Basics.identity )
--> [ -1, 5, 7, 8 ]Resulting type of Keys.identity.
import Map
import Order
import Float.Order
import N exposing (Up, To, N0)
import KeysSet
floatIncreasing : Keys.Identity Float Float.Order.Increasing
floatIncreasing =
Keys.identity Float.Order.increasing
KeysSet.fromList floatIncreasing [ -1.1, 5, 5, 8.7, 7.8 ]
|> KeysSet.toList ( floatIncreasing, Basics.identity )
--> [ -1.1, 5, 7.8, 8.7 ]Start a keys builder by giving names to the individual keys as arguments using a record
userKeys :
Keys
User
{ email : Key User (Order.By User.Email Email.Order) Email (Up N0 To N0) }
N1
userKeys =
Keys.for (\email -> { email = email })
|> Keys.by ( .email, User.email, Email.order )
Emptiable.empty
|> KeysSet.insert userKeys
{ name = "ben", email = "[email protected]" }
|> KeysSet.insert userKeys
{ name = "mai", email = "[email protected]" }
-- not inserted
-- There's already an element where .email is "[email protected]"Once you supply all the necessary key-Orderings with by,
a KeysBeingBuilt is automatically of type Keys.
So if you for example infer the type
KeysBeingBuilt element { yourKeys } { yourKeys } keyCountyou can replace it by
Keys element { yourKeys } keyCountIt's data is unaccessible because you shouldn't be able to
You won't need them if you just want to use KeysSet.
... It's safe to expose this information, tho, so why not make it available :)
List all keys in the keys record as an array
of functions
determining the Order of 2 elements
How to turn the element into the specified key
How to order by the specified key
A Key's distance from the first by in the Keys builder
The type of fully constructed
KeysBeingBuiltready to use."infer types" is your friend here
What's with those
Up N.. To N..? Internally, each key will be assigned an index. that type from bounded-nat preserves the knowledge that each key's index is less than the whole count.