Skip to content

Commit 01a98c0

Browse files
committed
add whenJust
1 parent 0bf29a7 commit 01a98c0

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

src/Element.elm

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module Element
4949
, spanAll
5050
, link
5151
, when
52+
, whenJust
5253
, within
5354
, above
5455
, below
@@ -96,7 +97,7 @@ By building your view with `Elements`, you have a single place to go to adjust o
9697
9798
@docs Element, Attribute
9899
99-
@docs empty, text, el, html, map
100+
@docs empty, text, el, html, map, when, whenJust
100101
101102
102103
# Layout
@@ -106,14 +107,14 @@ A layout element will explicitly define how it's children are layed out.
106107
Make sure to check out the Style Element specific attributes in `Element.Attributes` as they will help out when doing layout!
107108
108109
109-
## Text Layout
110+
## Linear Layouts
110111
111-
@docs textLayout, paragraph
112+
@docs row, column, wrappedRow, wrappedColumn
112113
113114
114-
## Linear Layouts
115+
## Text Layout
115116
116-
@docs row, column, wrappedRow, wrappedColumn
117+
@docs textLayout, paragraph
117118
118119
119120
## Grid Layout
@@ -123,7 +124,7 @@ Make sure to check out the Style Element specific attributes in `Element.Attribu
123124
124125
## Convenience Elements
125126
126-
@docs full, spacer, hairline, link, image, circle, break, when
127+
@docs full, spacer, hairline, link, image, circle, break
127128
128129
129130
## Positioning
@@ -1118,6 +1119,29 @@ when bool elm =
11181119
empty
11191120

11201121

1122+
{-| Another helper function that defaults to `empty`
1123+
1124+
whenJust (Just ("Hi!")) text
1125+
1126+
is sugar for
1127+
1128+
case maybe of
1129+
Nothing ->
1130+
empty
1131+
Just x ->
1132+
text x
1133+
1134+
-}
1135+
whenJust : Maybe a -> (a -> Element style variation msg) -> Element style variation msg
1136+
whenJust maybe view =
1137+
case maybe of
1138+
Nothing ->
1139+
empty
1140+
1141+
Just thing ->
1142+
view thing
1143+
1144+
11211145
{-| -}
11221146
within : List (Element style variation msg) -> Element style variation msg -> Element style variation msg
11231147
within nearbys parent =

0 commit comments

Comments
 (0)