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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:27:31+00:00 2026-05-23T09:27:31+00:00

II am trying to understand Scala collections by adding a new collection as follows:

  • 0

II am trying to understand Scala collections by adding a new collection as follows:

class NewColl[V](values:Vector[V],someOtherParams)
extends IndexedSeq[V] with IndexedSeqLike[V, NewColl[V]] {

  def fromSeq[V](seq: Seq[V]): NewColl[V] = ...

  override def newBuilder[V]: Builder[V, NewColl[V]] =
    new ArrayBuffer[V] mapResult fromSeq[V]
}

but I get the following error:

overriding method newBuilder in trait TraversableLike
   of type => scala.collection.mutable.Builder[V,NewColl[V]];
method newBuilder in trait GenericTraversableTemplate
   of type => scala.collection.mutable.Builder[V,IndexedSeq[V]] has incompatible type

Any Idea?

  • 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-23T09:27:32+00:00Added an answer on May 23, 2026 at 9:27 am

    What I do in similar cases is to look at what the standard library does in similar cases. Looking at concrete subclasses of IndexedSeq they seem to mix in GenericTraversableTemplate. With that in mind, reworking your code to use it I get:

    import collection.mutable._
    import collection.generic.GenericTraversableTemplate
    import collection.generic.GenericCompanion
    
    class NewColl[V](values:Vector[V]) extends IndexedSeq[V] with 
        GenericTraversableTemplate[V, NewColl] {
    
      def fromSeq[V](seq: Seq[V]): NewColl[V] = new NewColl(Vector(seq: _*))
    
      override def companion: GenericCompanion[NewColl] = new GenericCompanion[NewColl]() {
        def newBuilder[A]: Builder[A, NewColl[A]] = new Builder[A, NewColl[A]] {
          val elems = new ArrayBuffer[A]()
          def +=(a:A) = { elems += a; this } 
          def clear() { elems.clear }
          def result(): NewColl[A] = fromSeq(elems)
        }
      }
    
    }
    

    (with someOtherParams removed for clarity)

    Note that there are other questions on SO related to building classes on the scala 2.8 collection framework. For instance 5200505 which points to one of my favorite document The Architecture of Scala Collections. Also recently, Josh Suereth wrote a blog entry on creating your own collection class.

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

Sidebar

Related Questions

I am fairly new to Scala and am trying to understand the collections hierarchy.
I am fairly new to Scala. I am trying to understand how/if scala does
I am new to Scala, and was trying to understand match. When I try
I am trying to understand type members in Scala. I wrote a simple example
I'm trying to understand the behavior of Scala for-loop implicit box/unboxing of numerical types.
I'm trying to understand what Scala does with Case Classes that makes them somehow
I'm quite new to Scala programming language, and was trying something out stucked in
I'm trying to understand the advantages of currying over partial applications in Scala. Please
I'm trying to understand the implementation of List s in Scala. In particular I'm
I'm new to the Scala type system, and I'm trying to explore it via

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.