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

  • Home
  • SEARCH
  • 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 6127975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:34:27+00:00 2026-05-23T16:34:27+00:00

In the Circumflex framework , you can map an URL to a block like

  • 0

In the Circumflex framework, you can map an URL to a block like this:

get("/foo") = {
    "hello, world!"
}

which, when browsing to /foo, will show the given string as expected. Now, to write a complete web application, you almost always need some form of authentication and authorisation. I’m trying to write some kind of wrapper for the above construct, so I can write this:

get("/foo") = requireLogin {
    "hello, world!"
}

The requireLogin method would then check if the user is logged in, and if yes, execute the given block. If not, however, it should do a redirect to the login page.

Now I somehow can’t get the syntax right (i’m still a Scala newbie). How would you do this in a generic fashion?

  • 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-23T16:34:28+00:00Added an answer on May 23, 2026 at 4:34 pm

    Try something like this:

    def executeMaybe[A](work: => A): Option[A] =
      if (util.Random.nextBoolean)
        Some(work)
      else
        None
    

    This executes the passed code with probability 0.5, returning Some(<result delivered by work>), or returns None is the other cases. You can call it either like this:

    val v = executeMaybe(42)
    

    or with block notation:

    val v = executeMaybe {
      // do some work
      // provide return value
    }
    

    The trick is to use a by-name parameter, signalled by the => symbol. Read more e.g. here: http://daily-scala.blogspot.com/2009/12/by-name-parameter-to-function.html

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

Sidebar

Related Questions

I am looking at an algorithm that can map between characters with diacritics (
I am learning circumflex orm and using maven with idea for the first time.
I'm trying to use Circumflex ORM (as suggested on StackOverflow - here , here
I'm trying to find the best way to put circumflex accents ( ˆ =
I need a regex to count characters in a string which need 2 keystrokes
When I cut and paste from a Word document into VIM, quotes get translated
When you paste the following URL into IE: http://technet.microsoft.com/en-us/sysinternals/bb897434.aspx , the link on the
I have a table with a field which contains strings in my MySQL database.
I previously tried breaking this problem down into smaller, simpler problems here and here
Does scalatra use circumflex behind the scenes (or vise versa)? What are the key

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.