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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:48:42+00:00 2026-05-27T20:48:42+00:00

Given this pattern match: List(1,2,3) match { case head :: tail => println(>>> head=

  • 0

Given this pattern match:

List(1,2,3) match {
  case head :: tail => println(">>> head=" + head)
}

I’m assuming that ‘::’ is the case class found in scala.collection.immutable, but how is ‘::’ allowed to be written in that form (infix notation)? – is there a specific rule to allow for that?

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-05-27T20:48:43+00:00Added an answer on May 27, 2026 at 8:48 pm

    You can even write:

    val head :: tail = List(1, 2, 3)
    

    Basically anything where a pattern is expected (an assignment, a match statement or a line in a for-comprehension) can take an extractor, which is defined as an entity with an unapply method.

    One of the pieces of syntactic sugar that scala provides you with is that; if you have an extractor X(a, b), this can be written as a X b. Here’s an example with case classes (which have a default extractor):

    scala> case class X(a: Int, b: String)
    defined class X
    
    scala> val a X b = X(1, "two")
    a: Int = 1
    b: String = two
    

    The ability to write such entities infix extends to types as well:

    scala> type MappedTo[A, B] = Map[A, B]
    defined type alias MappedTo
    
    scala> def foo(m: Int MappedTo String) = m foreach println
    foo: (m: MappedTo[Int,String])Unit
    

    Note that in neither case, does scala restrict such infix operators to symbolic identifiers

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

Sidebar

Related Questions

In this piece of code, if I match the given pattern on the line,
I wrote this script which counts occurrences of particular pattern in a given file.
Given this class class Foo { // Want to find _bar with reflection [SomeAttribute]
Given this example: <img class=a /> <img /> <img class=a /> <img class=a id=active
I want to match everything in a string that does not match a given
This is more a design question than anything else... I really like Scala's case
The task I was trying to accomplish was that given an input pattern, e.g.
I'm looking for a way to get a list of files that match a
Given the pattern ^[a-zA-Z0-9 .\-_]+$ and the string te\\st , why is the match
Given this HTML: <ul id=topnav> <li id=topnav_galleries><a href=#>Galleries</a></li> <li id=topnav_information><a href=#>Information</a></li> </ul> And this

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.