Modules

README

Tree with Zipper

This is pure Elm rose tree
with zipper implementation.
In context of Elm, this data structure is mostly useful for building hierarchical interfaces
like menus, data browsers or filters.

Main features of this library are things like easy building tree structure from flat Lists
with very good performance characteristics, powerful and extensible zipper and feature-rich API.

Performance

Tree is using custom List like implementation (LList) to enable lazy level after level evaluation
of tree. In fact LList is just a function that construct plain old List. This id approach is the main performance optimization used in this library.

There is another library implementing same idea in slightly different way tomjkidd/elm-multiway-tree-zipper.
The main difference is that elm-multiway-tree-zipper implementation is strict so whole Tree is immediately evaluated.
Implementation provided by this package is optimalized for situations in which it isn't necessary to construct whole
structure immediately. In situations where Tree is expanded level by level this implementation yields
much better performance than strict implementation especially for large trees.
You can find basic comparison in performance.

This package is highly experimental and might change a lot over time.

Feedback and contributions to both code and documentation are very welcome.

Usage

As a pure Elm package preferable way to install is using elm package:

$ elm package install turboMaCk/lazy-tree-with-zipper

This is example of whole application that renders levels of items as nested tree
with toggling between open and closed state in every level:

Background

I've spent about a year experimenting with different ideas of Rose Tree implementation
optimized for needs of building UIs for recursive data. The biggest turned out to be performance.
Usually, data for web applications are coming from a server which uses SQL database as storage.
API usually then renders flat JSON or any other data format which uses references to describe recursive relationships.
Therefore one of the main features that are needed is an efficient and easy way to build tree from a list of data.
This usually results in exponential complexity. Since one item might be a child of multiple other things
there has to be at least one iteration over the whole list of data. Also by definition using such data
for building rose tree might result in infinity deep resulting tree.

Those are the things I've experimented with over time:

Strict based (Tree a (List a)) - not that great performance but OK until you hit too much recursion.

Lazy List based implementation (Tree a (LazyList a)) - runs into too much recursion even on simpler data.

Continuation Passing / CPS - very slow (hitting scripts runs for too long) - might have been an issue with a particular algorithm.

Lazy List construction - this is what this package is using - very best performance.

License

This package is released under BSD-3-Clause license. See LICENSE file for more info.