Converting between union and Maybe #2868
divanburger
started this conversation in
Ideas/Requests
Replies: 1 comment
-
We discussed this in the discord and it looks like |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When converting from an union to a Maybe I have to write code like this:
As it is not possible to convert directly from an union to a Maybe.
I though I could maybe write something like:
That unfortunately gives the error
Cannot convert untyped value 'nil' to 'int' from 'untyped nil'
as it is trying to convert thenil
directly to the type of the value first without realising that the Maybe supports both. The ternary operator works correctly though.My proposal is either making the
or_else
not try to convert to the type of the value and instead check the type that is supported by the context (the left-hand side of the assignment in this case), or maybe add syntax to convert from an union with a type assert to aMaybe
. Maybe something likesession.user_id = row["user_id"].?(int)
. I don't really like this syntax but maybe there is something similar that could work?session.user_id = row["user_id"].(Maybe(int))
wouldn't make sense as the union could have aMaybe(int)
in it.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions