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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:52:28+00:00 2026-06-13T01:52:28+00:00

I am trying to use the ::: method (is this an operator method?) from

  • 0

I am trying to use the ::: method (is this an operator method?) from List. Okay I know what it is doing now after typing in two lists in the REPL and seeing what was going on. However the API definition of the ::: method was hard to read and understand. I only “got it” by reading what it “returns”.

def :::[B >: A](prefix: List[B]): List[B]
    Adds the elements of a given list in front of this list.
    prefix  The list elements to prepend.
    returns list resulting from the concatenation of the given list prefix and this list.
    Example:  List(1, 2) ::: List(3, 4) = List(3, 4).:::(List(1, 2)) = List(1, 2, 3, 4)

In particular what does this part mean: [B >: A](prefix: List[B]). I mean I was able to understand what the method returns by reading what the method returns and playing with it. For the future, I would like to be able to read the API for a different method and try to understand everything. That is why I am asking this question.

  • 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-13T01:52:29+00:00Added an answer on June 13, 2026 at 1:52 am

    The two answers are both correct. You only have to remember that A is the type parameter of your current list, and B is the type parameter of the list you are supplying to :::

    If you are not yet confident, you can try your own definition of List

      class MyList[+A]{
        def :::[B >: A](prefix: MyList[B]): MyList[B] = new MyList[B]()
      }
    
      class Animal
      class Dog extends Animal
      class Pig extends Animal
      class Rock 
    

    And now you can test in the REPL:

    scala>  new MyList[Dog]
    res0: Test.AkkaTest.MyList[Test.AkkaTest.Dog] = Test.AkkaTest$MyList@190a0d51
    
    scala>  new MyList[Pig]
    res1: Test.AkkaTest.MyList[Test.AkkaTest.Pig] = Test.AkkaTest$MyList@1db5d2b2
    
    scala>  res0:::res1
    res2: Test.AkkaTest.MyList[Test.AkkaTest.Animal] = Test.AkkaTest$MyList@25927275
    
    scala>  new MyList[Rock]
    res3: Test.AkkaTest.MyList[Test.AkkaTest.Rock] = Test.AkkaTest$MyList@49f85a86
    
    scala>  res3:::res0
    res4: Test.AkkaTest.MyList[ScalaObject] = Test.AkkaTest$MyList@42130c2
    
    scala>  res0:::res3
    res5: Test.AkkaTest.MyList[ScalaObject] = Test.AkkaTest$MyList@6f24d504
    

    So you know should have understood that the ::: concatenates two list and creates a list whose generic type is the first common ancestor. This is because the type list is covariant, so for example you might think that, in case of res3 and res0 the compiler does the following:

    • A is Rock B is Dog, B is not a parent class of A, maybe I should throw compiler error?
    • But since MyList is covariant, MyList[Dog] is a subclass of MyList[ScalaObject].
    • Cool, ScalaObject is a parent class of Rock, so I will create a list of ScalaObject
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I'm trying to use this method to get my data into R, but
I'm trying to use that method this way: public void Method() { ThreadPool.QueueUserWorkItem(() =>
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
trying to use this route: from(activemq:profiles).aggregate(header(cheese)).batchSize(30).bean(ProfilesQueueService, saveContacts) Fails with: No signature of method: org.apache.camel.model.RouteType.aggregate()
Trying to use GridBagLayout. I have the method called buildLabel. This creates three label.
I'm trying to use depedency resolver inside a Web Api method. This worked fine
I am trying to use a fetcher method to retrieve items from my datastore.
I'm trying to use LINQ and I keep getting this error message: Operator '<'
I was trying to use the overload operator method to copy the entries of
I'm trying to use a method within the code of one windows form and

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.