This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
We were not able to find the expected elm-package.json file at this tag.
Tag 2.1.2
Committed At 2018-08-23 15:20:15 UTC



    2D Array library for Elm

    2D array library implemented using nested elm Arrays. Duplicates the elm Array API as much as possible, but with a row and column for every element. Useful for making data grids, as it provides row and column operations in addition to getting, setting, and mapping over cells.

    See the module docs for the complete list of operations:

      array2d =
          [ ["Row 1-Col 1", "Row 1-Col 2"]
          , ["Row 2-Col 1", "Row 2-Col 2"]
      changed =
        -- "Row 1-Col 1" becomes "NEW VALUE"
        Array2D.set 0 0 "NEW VALUE" array2d
      mappedArray =
          (\row col cell -> cell)
      -- Your app code here
      { model | dataGrid = mappedArray }

    Drawbacks and caveats

    Most examples of nested models in Elm use Lists of elements with a unique, constant ID, e.g.:

    type alias Cell = { uid : Int, ... }

    This allows messages to always be routed to the correct element, even if elements are re-ordered, removed, added, etc. If you use the index of an element instead to create a long-running Task that will change the element when it ends, be aware that the target element's index may have changed during the task!

    For data grids you are probably not going to be re-positioning cells. Most data grids simply modify cells in place, which is what Array2D is mainly intended for. The danger comes from inserting and deleting rows and columns. During such operations, you may want to temporarily make your grid "read-only" somehow.

    Why not use a single array with a 2D key?

    Honestly the nested approach was just easier to understand for all the row and column slicing and splicing that was needed for my use case, but it is probably slower for getting and setting individual elements. One could probably implement all the same row and column features using a single array in Elm and some clever code.