Is there a shorthand for the match
expression with isVertical
here?
let bulmaContentParentTile isVertical nodes =
let cssClasses =
let cssDefault = [ "tile"; "is-parent" ]
match isVertical with
| true -> cssDefault @ [ "is-vertical" ]
| _ -> cssDefault
div [ attr.classes cssClasses ] nodes
I assume that an expression like match isVertical with
is so common that there is a shorthand like the one we have for function
, no?
Yes, it's just an if
-expression:
let cssClasses =
let cssDefault = [ "tile"; "is-parent" ]
if isVertical then
cssDefault @ [ "is-vertical" ]
else cssDefault
Quoting from the F# docs:
Unlike in other languages, the
if...then...else
construct is an expression, not a statement. That means that it produces a value, which is the value of the last expression in the branch that executes.
It's a bit off-topic but you can build your list by using Sequence Expressions which is IMHO more readable for this use case.
let cssClasses = [
"tile"
"is-parent"
if isVertical then
"is-vertical"
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With