This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0 1.1.0
A list of values of any type, which can also be lists.
version 2.0.0
license BSD-3-Clause
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 2.0.0
Committed At 2018-03-17 17:36:18 UTC
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1

Modules

README

elm-nested-list

A list of values of any type, which can also be lists.

The main use case of this library is managing list of optional and nested values, for example, like Html nodes or Html.Attributes. Usually, we can solve this issue using List (List any) or List (Maybe any), like this:

myView : Bool -> Html msg
myView isHidden =
    Html.div []
        (List.concat
            [ [ Html.text "Always visible"
              , Html.text "Also always visible"
              ]
            , if isHidden then
                []
              else
                [ Html.text "Maybe visible" ]
            , if not isHidden then
                [ Html.text "Maybe not visible" ]
              else
                []
            ]
        )

Using NestedList, the above code will look like this:

myView : Bool -> Html msg
myView isHidden =
    Html.div []
        (NestedList.fromMany
            [ NestedList.one (Html.text "Always visible")
            , NestedList.one (Html.text "Always visible")
            , NestedList.ifTrue isHidden (Html.text "Maybe visible")
            , NestedList.ifFalse isHidden (Html.text "Maybe not visible")
            , NestedList many
                [ Html.text "Even nested list, without calling again fromMany"
                ]
            ]
        )

A Note About Performance

This library optimizes converting NestedList back to a list in linear time. Here is a benchmark comparing using NestedList against using List and List.concat.

Benchmark