Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7896527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:55:03+00:00 2026-06-03T07:55:03+00:00

Given snippet composes of method calls, which return an option type. I’d like to

  • 0

Given snippet composes of method calls, which return an option type. I’d like to call the next method if previous call returned None. I’m able to accomplish this with this snippet

def amountToPay : Option[TextBoxExtraction] =
  getMaxByFontsize(keywordAmountsWithCurrency) match {
    case None => getMaxByFontsize(keywordAmounts) match {
      case None  =>  highestKeywordAmount match {
        case None => getMaxByFontsize(amountsWithCurrency) match {
          case None => highestAmount
          case some => some
        }
        case some => some
      }
      case some => some
    }
    case some => some
  }

but it looks quite messy. So I hope there is abetter way to do it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:55:04+00:00Added an answer on June 3, 2026 at 7:55 am

    Yep, orElse is a little cleaner:

    def amountToPay : Option[TextBoxExtraction] =
      getMaxByFontsize(keywordAmountsWithCurrency)
        .orElse(getMaxByFontsize(keywordAmounts))
        .orElse(highestKeywordAmount)
        .orElse(getMaxByFontsize(amountsWithCurrency))
        .orElse(highestAmount)
    

    You could also just put the items in a Seq and then use something like xs.reduceLeft(_ orElse _) or xs.flatten.headOption.getOrElse(highestAmount).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following code snippet from inside a method; NSBezierPath * tempPath = [NSBezierPath
Given the following code snippet: $i= 11; function get_num() { global $i; return (--$i
Given the following code snippet: type MyIntf = interface ['{C6184693-663E-419F-B2DA-4DA1A0E33417}'] procedure Foo; end; InvisiblePropInterfaces
I am trying to convert the code snippet given in this http://www.movable-type.co.uk/scripts/latlong.html into java.
I'm looking for code which can do the following. Given a snippet of XML,
Given following snippet in a view: <style type=text/css> input[type=text] { width: <%: Model.CmsConfiguration.cms_form_width %>px;
Given the following snippet: function countZeroes(array) { function counter(total, element) { return total +
Given the next code snippet: ... - (void) setTotalAmount: (NSNumber*)input { [totalAmount autorelease]; totalAmount
Given the following snippet of HTML: Goggles <input type=checkbox id=id_goggles_opt_in name=goggles_opt_in> Approved <input type=checkbox
I have found a code snippet as given below which is used to disable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.