question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider adding Result.requireNonNull

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
cmeerencommented, Jul 21, 2019

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.

0reactions
danyx23commented, Jul 27, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found