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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:05:05+00:00 2026-06-09T04:05:05+00:00

I have a query result of List[ Tuple3[User, Order, OrderItem] ] To create a

  • 0

I have a query result of List[ Tuple3[User, Order, OrderItem] ]

To create a case class instance of an Invoice, its companion object takes a User, Order and a List[OrderItem].

Currently I’m hacking it out something like:

def getInvoice(orderNum: String): Option[Invoice] = {

  val res = 
    dao.byOrderNum(orderNum) // List[ Tuple3[User, OrderEntry, OrderItem] ]

  if(!res.isEmpty) {
    val(user, order) = (res(0)._1, res(0)._2)
    val items = res map { case(_, _, oi: OrderItem) => oi }
    Some( Invoices.apply(user, order, items) ) // gets an Invoice
  }
  else None
}

I could make the query result a List[ Option[Tuple3[User, Order, OrderItem]] ], which would let me flatMap over the result, but not sure what that buys me.

At any rate, must be a more concise/elegant solution to the problem

Thanks

  • 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-09T04:05:08+00:00Added an answer on June 9, 2026 at 4:05 am

    The following should be exactly equivalent:

    def getInvoice(orderNum: String): Option[Invoice] = {
      val res = dao.byOrderNum(orderNum)
    
      res.headOption.map {
        case (user, order, _) => Invoices(user, order, res.map(_._3))
      }
    }
    

    The key is headOption, which handles the checking for emptiness in a more idiomatic way (it gives None for an empty sequence and Some(xs.head) for a non-empty one).

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

Sidebar

Related Questions

i have a list of filter names: FILTERBYNAMES my query result items each contain
Imagine I have the following query: def result = Test.createCriteria().list(params) { // image here
I have a List<object[]> MyCollection which is a result of a SELECT SQL query.
I have a query with single result. The result is an anonymouse type. How
I would like to retrieve an ordered query result, but I need to have
I have a query that creates a result set like this: Rank Name 1
I have a query that returns a result set similar to the one below:
I have this query which returns a result set with Date(column) as nvarchar datatype.
Hi I have this Query and I'm getting an empty result, Anyone see anything
I have the following query with many LEFT JOIN clauses that has 7 result

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.