I often use list comprehension for optional values:
[Parent parent, Destination [DestPage currPage]] ++ [OpenChildren | parent == Bookmark 0]
But i do not know how to do a choice instead of optional value.
A lot of my code looks like this:
let lblTabX = if isAtBottom then 5 else 3
lblTabY = if isAtBottom then 3 else 60
lblTabPosition = Position left (if isAtBottom then bottom else top)
lblTabWidth = if isAtBottom then lblPageX - 60 else 20
lblTabHeight = if isAtBottom then 20 else pageHeight - 80
lblTabMargin = if isAtBottom then Margin 0 3 else Margin 3 0
As you see a lot of ifs :)
So i was playing with some operators and came up with this syntax:
iif c l r = if c then l else r
infixl 8 <-/
(<-/) l c = iif c l
infixl 8 /->
(/->) = ($)
And i like how the previous example now looks:
let lblTabX = 5 <-/ isAtBottom /-> 3
lblTabY = 3 <-/ isAtBottom /-> 60
lblTabPosition = Position left (bottom <-/ isAtBottom /-> top)
lblTabWidth = (lblPageX - 60) <-/ isAtBottom /-> 20
lblTabHeight = 20 <-/ isAtBottom /-> (pageHeight - 80)
lblTabMargin = Margin 0 3 <-/ isAtBottom /-> Margin 3 0
This is a toy example of course. I have no intention of using it. But i was just curious, is there a syntax to express the choice besides the if operator? Maybe with list comprehensions?