-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null Asserter #21
Comments
Can it be a function? there is a chance here to not introduce new syntax and make the scripts easier to understand using familiar concepts: contract assertions. https://rosettacode.org/wiki/Assertions_in_design_by_contract // core.dwl
fun require<T>(value: T | Null): T =
if (value == null)
fail('Value assertion failed')
else
value as T var myVar: String | Null = ???
fun acceptString(value: String) = ???
---
acceptString(require(myVar)) |
Yes @menduz this is a really valid point, but my concern with that is how verbose this end up being. I have mixed feelings about this. But you are 100% right that this can be modeled with the language in a very simple way |
I agree with @menduz here, having functions are more readable than something like Being verbose could be better than being confusing or difficult to understand. I can foresee people forgetting about |
Null Asserter
Current Problem
If we have a variable that is Something | Null but we have already validate that is not null or we
just know is never null.
This script fails beacuse
We currently have a way to assert that a property should exist
Fails because the property doesn't exists different to
That returns
null
but also different thatThat also returns null.
Having seen this we can not use
!
to assert that an expression doesn't returnnull
as this only asserts that a property does exists.Proposal
We can introduce
!!
this asserts that the expression is not null.The text was updated successfully, but these errors were encountered: