A better pattern would be to use Option/Maybe or Either.
If I have something like:
var a = null;
rather than using a?.b I would use:
const a = fromNullable(a);
const aValue = a.map(_ => _.b).getOrElse("No value");
You can further chain like
a.chain(_ => .b) .chain( => .c) .chain( => _.d)
In your anti-corruption layer convert all nulls to Option/Maybe and you don't have to deal with nulls.
I would love to not deal with null/undefined in JS.
JS
I find the ?. really elegant.
?.
But I also find Ruby elegant where things like this are normal.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A better pattern would be to use Option/Maybe or Either.
If I have something like:
var a = null;
rather than using a?.b I would use:
const a = fromNullable(a);
const aValue = a.map(_ => _.b).getOrElse("No value");
You can further chain like
a.chain(_ => .b)
.chain( => .c)
.chain( => _.d)
In your anti-corruption layer convert all nulls to Option/Maybe and you don't have to deal with nulls.
I would love to not deal with null/undefined in
JS
.I find the
?.
really elegant.But I also find Ruby elegant where things like this are normal.