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 1032341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:03:48+00:00 2026-05-16T14:03:48+00:00

There are a number of times I’ve run into a simple pattern when programming

  • 0

There are a number of times I’ve run into a simple pattern when programming in Java or C++ for which a custom control structure could reduce the boilerplate within my code. It goes something like:

 if( Predicate ){
     Action

     return Value
 }

that is, a “return if”-type statement. I’ve tried making functions with signature like foo[A,B]( pred:((A,A)=>Boolean), value:Option[B] ) but then I wind up checking if I’ve returned Some or None. I’m tripped up by the return statement.

Is there an inherit way of making such control structures in functional languages or more specifically Scala?

Edit:

I was not as clear with my description and it’s confusing people who are trying to help me. The key reason my foo doesn’t work is that it can’t short-circuit the evaluation of the containing function. That is

def intersect( geometry:Geometry, reference:Geometry ):Geometry = {
    return_if( withinBounds( geometry, projection ), logToString( logger, "Geometry outside " + projection.toString ), EmptyGeometry() )
    return_if( topologicallyCorrect( geometry ), intersect( correct( geometry ), reference )
    //rest of the function
}

and still allow for tail recursion within the return_if.

  • 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-05-16T14:03:48+00:00Added an answer on May 16, 2026 at 2:03 pm

    Hmm, as far as I understand it you want the return in the control structure to exit the function it is embedded in.

    So in your example it should exit the method intersect?

    I am not sure if thats possible. Because a return inside the return_if will always exit return_if and I don’t think there is a way to tell scala, that the return should exit the function return_if is embedded in.

    I hope I understood what you wanted to do 🙂

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

Sidebar

Related Questions

Is there a way of determining the number of times in which a particular
Is there a simple way of identifying the number of times a value is
Is there a way to control the number of times an iPhone app executes.
Is there an easy way to limit the number of times a view can
Is there MS SQL Server function that counts the number of times a particular
Is there a way I can have an excel track the number of times
In Javascript is there a function that returns the number of times that a
I have an images array in which there are number of images. Not fixed,
Is there a way to limit the number of times an application is used
Is there a function for MySQL that will count the number of times a

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.