This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0
A CRDT for sequential data based on LSEQ
version 1.1.0
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.1.0
Committed At 2018-06-26 16:26:39 UTC
mgold/elm-random-pcg 5.0.2 <= v < 6.0.0 5.0.2
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1
elm-community/list-extra 7.1.0 <= v < 8.0.0 7.1.0
elm-community/intdict 2.1.0 <= v < 3.0.0 2.1.0

Modules

README

Sequence

This is a prototype of a CRDT for sequential data written in Elm.

Work in progress! Use with caution.

Implementation stems from Nedelec et al. "LSEQ: an adaptive structure for sequences in distributed collaborative editing" (2013).

Example

module Main exposing (..)

import Sequence exposing (..)
import String
import Tuple
import Html exposing (div, li, text)


main =
    let
        path1 =
            alloc minPath maxPath

        path2 =
            alloc path1 maxPath

        path3 =
            alloc path2 maxPath

        concurrentPath =
            alloc path1 maxPath

        ops =
            [ createInsert "me" path1 'x'
            , createInsert "me" path2 'y'
            , createInsert "me" path3 'z'
            , createInsert "you" concurrentPath 'a'
            ]

        getChar value =
            case value of
                Value a ->
                    String.fromChar a
                        |> Just

                Tomb x ->
                    Nothing

        fold path entry lis =
            let
                item =
                    case entry of
                        Single origin (Value char) ->
                            String.fromChar char
                                |> text
                                |> (\x -> [ x ])
                                |> li []

                        Concurrent mvr ->
                            mvrToList mvr
                                |> List.filterMap (Tuple.second >> getChar)
                                |> List.intersperse ","
                                |> String.concat
                                |> text
                                |> (\x -> [ x ])
                                |> li []

                        _ ->
                            text ""
            in
                item :: lis
    in
        apply ops empty
            |> Tuple.first
            |> foldr fold []
            |> div []

Yields:

  • x
  • y,a
  • z

So x, y and z have been inserted by "me" while a has been inserted by "you" concurrently to y.

For a collaborative editor demo project as a more elaborated example see brightdb-text.