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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:58:32+00:00 2026-06-16T06:58:32+00:00

I am trying to iterate over a complex value inside a template using Scala

  • 0

I am trying to iterate over a complex value inside a template using Scala Play framework 2.

My variable is the following: tests: List[(String,Option[List[String]])]

I iterate on it like this:

@if(!tests.isEmpty) {
<h3>Tests results</h3>
@tests.map(t => {

<h4>@t._1</h4>

@t._2 match {
case None => {
<p>
  <span>
    [WARNING] Test failed
  </span>
</p>
}
case Some(res) {
@res.map(r => {
<p>
  <span>
    @r
  </span>
</p>
})}
}

})}

but I got the following error: expected start of definition on @t._2 match {.

I guessed that the problem comes from the fact that I use a tuple inside a map. But why? Is there any solution?

  • 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-16T06:58:34+00:00Added an answer on June 16, 2026 at 6:58 am

    The problem lies in the way you’re using curly braces and parenthesis with map. Everything inside the parenthesis will be treated as scala code. You won’t be able to use html and to use the @ as you’re expecting it to work. Inside the curly braces you can use the @ that way you want.

    For instance, this won’t compile and will raise the expected start of definition:

    @(tests: List[(String,Option[List[String]])])
    
    <h3>Tests results</h3>
    
    @tests.map( t => {  
      <h4>@t._1</h4>
      @t._2
    })
    

    On the other hand, this will compile and work the way it’s supposed to:

    @(tests: List[(String,Option[List[String]])])
    
    <h3>Tests results</h3>
    
    @tests.map{ t =>   
      <h4>@t._1</h4>
      @t._2
    }
    

    I had had problems with the way the template parses the scala code. I’m not entirely sure if they parse it the way the scala compiler parses a scala code. I’ve read before that there’re some limitations. And I’ll show you one in a bit. Your solution compiles and works just fine if you switch the curly braces. And you’ll end up with something like that:

    @(tests: List[(String,Option[List[String]])])
    
    <h3>Tests results</h3>
    
    @tests.map{  t =>  
    <h4>@t._1</h4>
    
    @defining(t._2) { optLst => 
      @optLst match {
        case None => {
            <p>
              <span>
                [WARNING] Test failed
              </span>
            </p>
        }
        case Some(res) => {
            @res.map{r => 
            <p>
              <span>
                @r
              </span>
            </p>
            }
        }
      }
    }
    
    }
    

    This is not the most idiomatic way to do it. I would probably use a map instead of pattern matching there. But use what fits you. The point here is that @defining there. Have you noticed it? If you try to match with t._2 directly you’ll get a ')' expected but 'case' found. exception. What is odd to me. And I’ve found that before and I’ve googled it a lot to find out that this is a problem in the current engine and that you have to define the value and then match it the way you want to.

    Cheers!

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

Sidebar

Related Questions

I am trying to iterate over a mongo DBCursor in a play framework 2.0.1
I am trying to iterate over a list and trying to print the value
I'm trying to iterate over a value list and convert it into a string.
I'm trying to iterate over an enum, and call a method using each of
I've been trying to figure out how to iterate over the list of columns
Im trying to iterate over a nestled dict list. The first level works fine.
I'm trying to iterate over a map in c++ using openMP, but I got
I'm trying to iterate over the class files in a known directory using streams.
I am trying to iterate over list of controls to determine which checkboxes are
I'm trying to iterate over a ListDictionary (C# StringTemplate) in a template and have

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.