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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:35:40+00:00 2026-05-28T17:35:40+00:00

Edit originally the question was Collection to Tuple as I assumed I needed a

  • 0

Edit

originally the question was “Collection to Tuple” as I assumed I needed a tuple in order to do variable multi-assignment. It turns out that one can do variable multi-assignment directly on collections. Retitled the question accordingly.

Original
Have a simple Seq[String] derived from a regex that I would like to convert to a Tuple.

What’s the most direct way to do so?

I currently have:

val(clazz, date) = captures match {
  case x: Seq[String] => (x(0), x(1))
}

Which is ok, but my routing layer has a bunch of regex matched routes that I’ll be doing val(a,b,c) multi-assignment on (the capture group is always known since the route is not processed if regex does not match). Would be nice to have a leaner solution than match { case.. => ..}

What’s the shortest 1-liner to convert collections to tuples in Scala?

  • 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-28T17:35:42+00:00Added an answer on May 28, 2026 at 5:35 pm

    This is not an answer to the question but might solve the problem in a different way.

    You know you can match a xs: List[String] like so:

    val a :: b :: c :: _ = xs 
    

    This assigns the first three elements of the list to a,b,c? You can match other things like Seq in the declaration of a val just like inside a case statement. Be sure you take care of matching errors:

    Catching MatchError at val initialisation with pattern matching in Scala?

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

Sidebar

Related Questions

Edit: Originally I had a simple form Ajax script that wasn't working, turns out
Edit: I originally left out what may be an important detail from my question
Edit: From another question I provided an answer that has links to a lot
EDIT : Re-written this question based on original answer The scala.collection.immutable.Set class is not
EDIT: This question title originally was: How does Doctrine know last inserted id in
EDIT: This question was originally about checkboxes, but I am getting the same behavior
This is a question that extends from the originally posted here: Link to loading-xaml
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
this is an edit of the original post now that I better understand the
Edit: This question was written in 2008, which was like 3 internet ages ago.

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.