jinjor/elm-insertable-key - version: 1.0.1

for more information visit the package's GitHub page

Package contains the following modules:

elm-insertable-key

Build Status

Generates a new key between two keys.

What is this?

If you want to insert new record between B and C,

|id|sort_key| |:--|:--| |A|1| |B|2| |C|3| |D|4|

This library gives you a new key 21.

|id|sort_key| |:--|:--| |A|1| |B|2| |E|21| |C|3| |D|4|

This can be useful, when you use RDB and change the order without rearranging all of the rows.

Example

import InsertableKey exposing (Key, after, before, between, init)

generateThreeKeys : Maybe ( Key, Key, Key )
generateThreeKeys =
    let
        left =
            init
    in
    after left
        |> Maybe.andThen
            (\right ->
                between left right
                    |> Maybe.map
                        (\center ->
                            ( left, center, right )
                        )
            )

How it works?

Help wanted!

This works well at least for my use case, but there should be better algorithm to do this.

If you have some information about this problem, please let me know. Forking and publishing your own is also welcome!

LICENSE

BSD-3-Clause