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
Hello, sometimes I have several values of type Expr (Maybe a) and would like to take the first non-null value, or null if they are all null.
Intuitively I would write v1 <|> v2 but we get this error:
No instance for (GHC.Base.Alternative Expr)
arising from a use of ‘<|>’
Fair enough.
I have found the operator <|>: but it seems to apply to tables, not to expressions 🤔
For now I have written the following:
--| Take the first non-null value, otherwise return null.-- This is similar to the Alternative `<|>` operator for `Maybe`, but in the `Expr` context.orElse:: (NotNulla, DBTypea) =>Expr (Maybea) ->Expr (Maybea) ->Expr (Maybea)
orElse ma1 ma2 = nullable ma2 nullify ma1
But it feels clunky, and I am surprised there isn't an idiomatic way to do it in Rel8.
Have I missed something?
If not, how about adding such a function/support in Rel8?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, sometimes I have several values of type
Expr (Maybe a)
and would like to take the first non-null value, or null if they are all null.Intuitively I would write
v1 <|> v2
but we get this error:Fair enough.
I have found the operator <|>: but it seems to apply to tables, not to expressions 🤔
For now I have written the following:
But it feels clunky, and I am surprised there isn't an idiomatic way to do it in Rel8.
Have I missed something?
If not, how about adding such a function/support in Rel8?
Beta Was this translation helpful? Give feedback.
All reactions