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.

Do you consider implementing `Maybe#orElse()` method?

See original GitHub issue

Hi, thanks for the lib. Love it! ❤️

Do you find Maybe#orElse() method useful and consider implementing it? I find it useful in order to gracefully avoid such constructions:

let maybeGTINs = getGTINsFromString(string);
if (maybeGTINs.isNone()) {
  let maybeGTINs = just(['default']);
}

with something like this:

const maybeGTINs = getGTINsFromString(string).orElse(['default']);

Monet’s seem to have one, but it accepts a Maybe instance for some reason. I guess, the best implementation would be the one mentioned in this article: https://jrsinclair.com/articles/2016/marvellously-mysterious-javascript-maybe-monad/

Maybe.prototype.orElse = function(default) {
    if (this.isNothing()) {
        return Maybe.of(default);
    }

    return this;
};

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lancediksoncommented, Aug 13, 2020

Wow, that was fast! Thank you!

1reaction
lancediksoncommented, Aug 12, 2020

Great! I have some spare time, so if you would like me to propose a PR, just let me know 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

When to use Optional.orElse() rather than Optional.orElseGet()
orElse() will always call the given function whether you want it or not, regardless of Optional.isPresent() value · orElseGet() will only call ...
Read more >
Java 8 Optional isPresent(), OrElse() and get() Examples
You can see that the OrElse() method is much nicer than the combination of isPresent() and get(). It not only removes the check...
Read more >
12 recipes for using the Optional class as it's meant to be used
So the rule here is to use orElse() when you have already preconstructed values and you don't use an expensive computed value.
Read more >
Java Optional - orElse() vs orElseGet() - Baeldung
In this article, we learned the nuances between the Optional orElse() and OrElseGet() methods. We also discussed how such simple concepts can ......
Read more >
26 Reasons Why Using Optional Correctly Is Not Optional
A typical scenario for using orElse(null) occurs when we have an Optional and we need to call a method that accepts null references...
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