ryanstull / scalanullsafe Goto Github PK
View Code? Open in Web Editor NEWA macro-based library for writing efficient and readable null-safe code in Scala.
License: MIT License
A macro-based library for writing efficient and readable null-safe code in Scala.
License: MIT License
If there is a function call in the expression passed to the macros: i.e:
?(SomeFunc(a.b).c)
Currently the macros will fail, but the macros could handle this case if it considers the function as part of the first transformation. I.e.
if (a!=null){
val b_prime = SomeFunc(a.b)
if(b_prime != null) {
b_prime.c
} else null
} else null
Currently there's no equivalent in ScalaNullSafe for
Option(a).flatmap(a => f(a))
In other words, you can't use the result of a null-safe selection in a function call.
Adding the .?
extension method to all AnyRef
objects would solve this issue.
?(a.asInstanceOf[A].b)
will fail.
val a: String = null
?(a.toInt) // throws NumberFormatException
The above snippet fails due to Scala wrapping a in an implicit class and the macro not knowing how to check for null properly in this instance. The snippet below is what the above code compiles to. The macro should instead check if a is !=
null and apply the wrapper in the body of the if.
{
<synthetic> val fresh$macro$1: scala.collection.StringOps = scala.Predef.augmentString(a);
if (fresh$macro$1.$bang$eq(null))
fresh$macro$1.toInt
else
null
}
Currently ?
and ??
have different syntax for default args. They should ideally be the same.
Compare against:
Simple access (Unsafe)
Manual full safety
Option flatmap
For loop, option flatmap
Nullsafe navigator lambda
Simple catch NPE
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.