You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have found it useful when building views to be able to conditionally include an Attribute or child element. It seem natural to use Maybe to represent this conditional nature. However I usually only have one conditional attribute and several unconditional attributes so it feels a little awkward and overkill to wrap many elements in Just and then call filterMap identity. I would prefer to write the list literal and then conditionally add items.
maybeCons:Maybea->Lista->ListamaybeCons maybeItem list =case maybeItem ofJust item -> item :: list
Nothing-> list
For example when a tabbed container, I want to only attach click handlers to the non selected tabs to simplify my update logic.
let (editOnClick, previewOnClick)=case model.editorTab of Edit draft ->(Nothing,Just<| onWithOptions
"click"(OptionsTrueTrue)(Json.Decode.succeed <|SetEditorTab<|Preview draft model.user.theme ))Preview draft theme ->(Just<| onWithOptions
"click"(OptionsTrueTrue)(Json.Decode.succeed <|SetEditorTab<|Preview draft model.user.theme ),Nothing)in
div [ id Editor][ div [ class EditorHeader][ nav [ class HorizontalTabNav][ button
( maybeCons
editOnClick
[ class HorizontalTab, action "/comments/edit"-- fallback for no JS, yeah yeah yeah XSS we handle it., method "post"])[ text "Edit"], button
( maybeCons
previewOnClick
[ class HorizontalTab, action "/comments/preview"-- fallback for no JS, method "post"])[ text "Preview"]]], viewEditorTab
]
Cons
Haskell does not feel the need to implement this. It is really simple function anyone can write if they really need it.
The text was updated successfully, but these errors were encountered:
Hey that looks pretty cool. Ive been in your situation, but I usually had something a bit clunkier, like a function called buttonAttributes : Bool -> List Attribute.
I have found it useful when building views to be able to conditionally include an Attribute or child element. It seem natural to use Maybe to represent this conditional nature. However I usually only have one conditional attribute and several unconditional attributes so it feels a little awkward and overkill to wrap many elements in Just and then call
filterMap identity
. I would prefer to write the list literal and then conditionally add items.For example when a tabbed container, I want to only attach click handlers to the non selected tabs to simplify my update logic.
Cons
Haskell does not feel the need to implement this. It is really simple function anyone can write if they really need it.
The text was updated successfully, but these errors were encountered: