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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:04:06+00:00 2026-06-02T19:04:06+00:00

I have an input something like this: 1 2 3 4 5 . What

  • 0

I have an input something like this: "1 2 3 4 5".

What I would like to do, is to create a set of new variables, let a be the first one of the sequence, b the second, and xs the rest as a sequence (obviously I can do it in 3 different lines, but I would like to use multiple assignment).

A bit of search helped me by finding the right-ignoring sequence patterns, which I was able to use:

val Array(a, b, xs @ _*) = "1 2 3 4 5".split(" ")

What I do not understand is that why doesn’t it work if I try it with a tuple? I get an error for this:

val (a, b, xs @ _*) = "1 2 3 4 5".split(" ")

The error message is:

<console>:1: error: illegal start of simple pattern

Are there any alternatives for multiple-assignment without using Array?

I have just started playing with Scala a few days ago, so please bear with me 🙂 Thanks in advance!

  • 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-02T19:04:08+00:00Added an answer on June 2, 2026 at 7:04 pm

    Other answers tell you why you can’t use tuples, but arrays are awkward for this purpose. I prefer lists:

    val a :: b :: xs = "1 2 3 4 5".split(" ").toList
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
i have done something like this: <form action=validate.php method=get> Id :<input type=text name=pID/><br/><br/> Name
So the have seem something like this today: $$('input').each(function() { // do something });
Hey i would like do have your input on this I use this to
I have something like the following <div id=container> <ul id=name_list> <li class=name> <input type=hidden
I have this code in Python inputted = input(Enter in something: ) print(Input is
I have a Silverlight 3 project with something like this: <ItemGroup> <Content Include=Content\image1.png> </Content>
So I have a a text file that looks something like this: public >ret
I have a user input form here: http://www.7bks.com/create (Google login required) When you first
Let's say I have two Databases like so : DatabaseA create table Table1 (

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.