Consider adding Result.requireNonNull
See original GitHub issueI really like this library! I just found myself wanting a function that takes a nullable value and makes sure that it is not null by turning it into an Error value if it is null (useful for the many dotnet function that might return null). Would you consider a PR that adds something like the code below?
let requireNotNull (errorValue : 'error) (value : 'a when 'a : null ) =
match value with
| null -> Error errorValue
| nonnull -> Ok nonnull
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Why should one use Objects.requireNonNull()?
Using requireNonNull() as first statements in a method allow to identify right now/fast the cause of the exception. The stacktrace indicates ...
Read more >Is using Objects.requireNonNull() in production bad practice?
requireNonNull is a helpful method to spot NullPointerExceptions effectively while developing. But in fact it's throwing a RuntimeException ...
Read more >Possible false positives using Objects.requireNonNull? #276
Hi there,. Consider the following code: @Nullable CustomValue value; // member variable ... public void doSomething() { value = dao.
Read more >Avoid Check for Null Statement in Java
Learn several strategies for avoiding the all-too-familiar boilerplate conditional statements to check for null values in Java.
Read more >@NonNull
Overview. You can use @NonNull on a record component, or a parameter of a method or constructor. This will cause to lombok generate...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The helper function makes sense to me. 🙂
I’d call it requireNotNull (as OP suggested) instead of requireNonNull though, to fit with other functions (e.g. notEqualTo) (and in my mind it sounds better), but I certainly don’t want to create a fuss over the difference.
Looks good. I have some strange issue with the update of the nuget file in the project that I am using this but the assembly has the new code and everything should work so I’m closing the issue.