Hi all,
Regularly my view functions have a structure like this:
div
[ class "wrapper" ]
[ div
[ class "first" ]
( List.map viewListItems list )
, div
[ class "second" ]
[ text "Some stuff" ]
]
This will render an div.first without child nodes, when list is an empty list.
I would like to avoid these ‘empty’ divs. I could do this like this:
let
firstDiv =
case list of
[] -> []
_ ->
[ div
[ class "first" ]
( List.map viewListItems list )
]
in
div
[ class "content" ]
( List.concat
[ firstDiv
, [ div
[ class "second" ]
[ text "Some stuff" ]
]
]
)
However, this method decreases the readability of the function by replacing the logic and the viewListItems function to the let block.
Do you know a nicer way to do this? E.g. could I write a function to filter away html-elements without child nodes?