final object CollectionStrawMan6
extends LowPriority

A strawman architecture for new collections. It contains some example collection classes and methods with the intent to expose some key issues. It would be good to compare this to odether implementations of the same functionality, to get an idea of the strengths and weaknesses of different collection architectures.

For a test file, see tests/run/CollectionTests.scala.

Strawman6 is like strawman5, and adds lazy lists (i.e. lazie streams), arrays and some utilitity methods (take, tail, mkString, toArray). Also, systematically uses builders for all strict collections.

Types covered in this strawman:

  1. Collection base types:

    IterableOnce, Iterable, Seq, LinearSeq, View, IndexedView
    
  2. Collection creator base types:

    FromIterable, IterableFactory, Buildable, Builder
    
  3. Types that bundle operations:

    IterableOps, IterableMonoTransforms, IterablePolyTransforms, IterableLike
    SeqMonoTransforms, SeqLike
    
  4. Concrete collection types:

    List, LazyList, ListBuffer, ArrayBuffer, ArrayBufferView, StringView, ArrayView
    
  5. Decorators for existing types

    StringOps, ArrayOps
    
  6. Related non collection types:

    Iterator, StringBuilder
    

Operations covered in this strawman:

  1. Abstract operations, or expected to be overridden:

    For iterables:

    iterator, fromIterable, fromIterableWithSameElemType, knownLength, className

    For sequences:

    apply, length

    For buildables:

    newBuilder

    For builders:

    +=, result

  2. Utility methods, might be overridden for performance:

    Operations returning not necessarily a collection:

    foreach, foldLeft, foldRight, indexWhere, isEmpty, head, size, mkString

    Operations returning a collection of a fixed type constructor:

    view, to, toArray, copyToArray

    Type-preserving generic transforms:

    filter, partition, take, drop, tail, reverse

    Generic transforms returning collections of different element types:

    map, flatMap, ++, zip

Constructors

Members

case class ::
final object ::
class ArrayBuffer

Concrete collection type: ArrayBuffer

Concrete collection type: ArrayBuffer

final object ArrayBuffer
class ArrayBufferView
trait ArrayLike

A trait representing indexable collections with finite length

A trait representing indexable collections with finite length

final class ArrayOps

Decorator to add collection operations to arrays.

Decorator to add collection operations to arrays.

final object ArrayOps

Decorator to add collection operations to arrays.

Decorator to add collection operations to arrays.

case class ArrayView
final object ArrayView
trait Buildable

Base trait for strict collections that can be built using a builder.

Base trait for strict collections that can be built using a builder.

trait Builder

Base trait for collection builders

Base trait for collection builders

trait FromIterable

Base trait for instances that can construct a collection from an iterable

Base trait for instances that can construct a collection from an iterable

final object IndexedView
trait IndexedView

View defined in terms of indexing a range

View defined in terms of indexing a range

trait Iterable

Base trait for generic collections

Base trait for generic collections

trait IterableFactory

Base trait for companion objects of collections

Base trait for companion objects of collections

[+] trait IterableLike

Base trait for Iterable operations

VarianceNote

We require that for all child classes of Iterable the variance of the child class and the variance of the...

Base trait for Iterable operations

VarianceNote

We require that for all child classes of Iterable the variance of the child class and the variance of the C parameter passed to IterableLike are the same. We cannot express this since we lack variance polymorphism. That's why we have to resort at some places to write C[A @uncheckedVariance].

Type-preserving transforms over iterables. Operations defined here return in their result iterables of the same type as the one they are invoked on.

Type-preserving transforms over iterables. Operations defined here return in their result iterables of the same type as the one they are invoked on.

trait IterableOnce

Iterator can be used only once

Iterator can be used only once

trait IterableOps

Operations over iterables. No operation defined here is generic in the type of the underlying collection.

Operations over iterables. No operation defined here is generic in the type of the underlying collection.

Transforms over iterables that can return collections of different element types.

Transforms over iterables that can return collections of different element types.

final object Iterator
trait Iterator

A core Iterator class

A core Iterator class

class LazyList
final object LazyList
trait LinearSeq

Base trait for linearly accessed sequences that have efficient head and tail operations. Known subclasses: List, LazyList

Base trait for linearly accessed sequences that have efficient head and tail operations. Known subclasses: List, LazyList

trait LinearSeqLike

Base trait for linear Seq operations

Base trait for linear Seq operations

final object List
sealed trait List

Concrete collection type: List

Concrete collection type: List

class ListBuffer

Concrete collection type: ListBuffer

Concrete collection type: ListBuffer

final object ListBuffer
final object Nil
trait Seq

Base trait for sequence collections

Base trait for sequence collections

trait SeqLike

Base trait for Seq operations

Base trait for Seq operations

trait SeqMonoTransforms

Type-preserving transforms over sequences.

Type-preserving transforms over sequences.

class StringBuilder
final class StringOps

Decorator to add collection operations to strings.

Decorator to add collection operations to strings.

final object StringOps

Decorator to add collection operations to strings.

Decorator to add collection operations to strings.

case class StringView
final object StringView
final object View

This object reifies operations on views as case classes

This object reifies operations on views as case classes

trait View

Concrete collection type: View

Concrete collection type: View

type IndexedSeq = Seq [ +A ]
implicit def ArrayOps ( xs: Array [ A ] ) : ArrayOps [ A ]

Decorator to add collection operations to arrays.

Decorator to add collection operations to arrays.

implicit def StringOps ( s: String ) : StringOps

Decorator to add collection operations to strings.

Decorator to add collection operations to strings.