Skip to content
This repository was archived by the owner on Mar 19, 2018. It is now read-only.

alvivi/elm-nested-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEPRECATED Use elm-keyword-list) instead.

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages