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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:24:25+00:00 2026-05-30T12:24:25+00:00

When trying to answer this question : Leave off underscore in function literal I

  • 0

When trying to answer this question : Leave off underscore in function literal I tried to code an example and I faced a strange behavior.

scala> val myList = 1::2::Nil
myList: List[Int] = List(1, 2)

scala> def concat:(List[Int]=> List[Int]) = myList:::
concat: (List[Int]) => List[Int]

scala> concat(3::Nil)
res1: List[Int] = List(3, 1, 2)

While I have the good answer when I use _or x=> f(x) syntaxes.

scala> def concat0:(List[Int]=> List[Int]) = x=> myList:::x
concat0: (List[Int]) => List[Int]

scala> def concat1:(List[Int]=> List[Int]) = myList::: _
concat1: (List[Int]) => List[Int]

scala> concat0(3::Nil)
res2: List[Int] = List(1, 2, 3)

scala> concat1(3::Nil)
res3: List[Int] = List(1, 2, 3)

Is there a rational explanation why myList comes after 3::Nilin the function concat?

  • 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-30T12:24:27+00:00Added an answer on May 30, 2026 at 12:24 pm

    myList ::: _ translates to _.:::(myList), whereas myList ::: translates to myList.:::(_).

    tl;dr

    This post goes into more detail about right associative methods. What’s happening here is:

    • def concat0:(List[Int]=> List[Int]) = x=> myList:::x
      • Scala compiler can infer that x if of type List[Int]
      • List has a ::: method
      • Because of the rules of right associativity, this turns into x.:::(myList), which prepends myList to x.
    • def concat:(List[Int]=> List[Int]) = myList:::
      • myList if of type List[Int]
      • There is no right hand side of :::, so there’s no right-associativity
      • Instead, compiler infers a . between myList and :::
      • myList.::: is the same as x => myList.:::(x), which prepends x to myList.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to answer this question I found that the code int* p =
In trying to answer this question I came up with the following code: #include
(Came up with this question in the course of trying to answer this other
I have looked around on the Internet trying to answer this question. It seems
This question is a result of what i noticed while trying to answer another
I've been searching around trying to find an answer to this question, and I
I'm trying to implement the answer to this SO question . The problem is:
In trying to answer this question for myself I came across this nugget, after
I was trying to answer this question. As suggested by the accepted answer, the
Trying to answer this question , I created this Python regular expression to match

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.