package collection
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:
- 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:
- 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
- Alphabetic
- By Inheritance
- collection
- LowPriority
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
ArrayLike
[+A] extends Any
A trait representing indexable collections with finite length
- final class ArrayOps [A] extends AnyVal with IterableOps[A] with SeqMonoTransforms[A, Array[A]] with Buildable[A, Array[A]] with ArrayLike[A]
- case class ArrayView [A](xs: Array[A]) extends IndexedView[A] with Product with Serializable
-
trait
BitSet
extends SortedSet[Int] with BitSetLike[BitSet]
Base type of bitsets
-
trait
BitSetFactories
[+C] extends AnyRef
Factory methods for unconstrained collections of kind
* -
trait
BitSetLike
[+C <: BitSet] extends SortedSetLike[Int, SortedSet] with BitSetMonoTransforms[C]
Base implementation type of bitsets
- trait BitSetMonoTransforms [+C <: BitSet] extends SetMonoTransforms[Int, C]
-
trait
FromIterable
[+C[X] <: Iterable[X]] extends AnyRef
Base trait for instances that can construct a collection from an iterable
- trait IndexedSeq [+A] extends Seq[A]
-
trait
IndexedView
[+A] extends View[A] with ArrayLike[A]
View defined in terms of indexing a range
-
trait
Iterable
[+A] extends IterableOnce[A] with IterableLike[A, Iterable]
Base trait for generic collections
-
trait
IterableFactories
[+C[X] <: Iterable[X]] extends FromIterable[C]
Base trait for companion objects of collections
-
trait
IterableLike
[+A, +C[X] <: Iterable[X]] extends FromIterable[C] with IterableOps[A] with IterableMonoTransforms[A, C[A]] with IterablePolyTransforms[A, C]
Base trait for Iterable operations
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
Cparameter passed toIterableLikeare the same. We cannot express this since we lack variance polymorphism. That's why we have to resort at some places to writeC[A @uncheckedVariance]. -
trait
IterableMonoTransforms
[+A, +Repr] extends Any
Type-preserving transforms over iterables.
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 [+A] extends AnyRef
-
trait
IterableOps
[+A] extends Any
Operations over iterables.
Operations over iterables. No operation defined here is generic in the type of the underlying collection.
-
trait
IterablePolyTransforms
[+A, +C[A]] extends Any
Transforms over iterables that can return collections of different element types.
-
trait
Iterator
[+A] extends IterableOnce[A]
A core Iterator class
-
trait
LinearSeq
[+A] extends Seq[A] with LinearSeqLike[A, LinearSeq]
Base trait for linearly accessed sequences that have efficient
headandtailoperations.Base trait for linearly accessed sequences that have efficient
headandtailoperations. Known subclasses: List, LazyList -
trait
LinearSeqLike
[+A, +C[X] <: LinearSeq[X]] extends SeqLike[A, C]
Base trait for linear Seq operations
-
trait
Map
[K, +V] extends Iterable[(K, V)] with MapLike[K, V, Map]
Base Map type
-
trait
MapFactories
[C[_, _]] extends AnyRef
Factory methods for collections of kind
* −> * -> * -
trait
MapLike
[K, +V, +C[X, Y] <: Map[X, Y]] extends IterableLike[(K, V), Iterable] with IterableMonoTransforms[(K, V), C[K, V]] with MapPolyTransforms[K, V, C]
Base Map implementation type
-
trait
MapPolyTransforms
[K, +V, +C[X, Y] <: Map[X, Y]] extends IterablePolyTransforms[(K, V), Iterable]
Polymorphic transformation methods
-
trait
OrderingGuidedFactories
[C[_]] extends AnyRef
Factories for collections whose elements require an ordering
-
trait
Seq
[+A] extends Iterable[A] with SeqLike[A, Seq] with ArrayLike[A]
Base trait for sequence collections
-
trait
SeqLike
[+A, +C[X] <: Seq[X]] extends IterableLike[A, C] with SeqMonoTransforms[A, C[A]] with Equals
Base trait for Seq operations
-
trait
SeqMonoTransforms
[+A, +Repr] extends IterableMonoTransforms[A, Repr]
Type-preserving transforms over sequences.
-
trait
Set
[A] extends Iterable[A] with SetLike[A, Set]
Base trait for set collections
-
trait
SetLike
[A, +C[X] <: Set[X]] extends IterableLike[A, C] with SetMonoTransforms[A, C[A]] with Equals
Base trait for set operations
-
trait
SetMonoTransforms
[A, +Repr] extends IterableMonoTransforms[A, Repr]
Monomorphic transformation operations
-
trait
Sorted
[A] extends SortedLike[A, Sorted[A]]
Base trait for sorted collections
- trait SortedLike [A, +Repr] extends AnyRef
-
trait
SortedPolyTransforms
[A, +C[X] <: Sorted[X]] extends IterablePolyTransforms[A, Iterable]
Polymorphic transformation methods on sorted collections
-
trait
SortedSet
[A] extends Set[A] with Sorted[A] with SortedSetLike[A, SortedSet]
Base type of sorted sets
- trait SortedSetLike [A, +C[X] <: SortedSet[X]] extends SortedLike[A, C[A]] with SortedPolyTransforms[A, C] with SetLike[A, Set] with SetMonoTransforms[A, C[A]]
- final class StringOps extends AnyVal with IterableOps[Char] with SeqMonoTransforms[Char, String] with IterablePolyTransforms[Char, List] with Buildable[Char, String] with ArrayLike[Char]
- case class StringView (s: String) extends IndexedView[Char] with Product with Serializable
-
trait
View
[+A] extends Iterable[A] with IterableLike[A, View]
Concrete collection type: View
- implicit final class toNewIterator [A] extends AnyVal
- implicit final class toNewSeq [A] extends AnyVal
- implicit final class toOldIterator [A] extends AnyVal
- implicit final class toOldSeq [A] extends AnyVal
Value Members
-
implicit
def
arrayToArrayOps[A](as: Array[A]): ArrayOps[A]
Decorator to add collection operations to arrays.
-
implicit
def
arrayToView[T](xs: Array[T]): ArrayView[T]
Convert array to iterable via view.
Convert array to iterable via view. Lower priority than ArrayOps
- Definition Classes
- LowPriority
-
implicit
def
stringToStringOps(s: String): StringOps
Decorator to add collection operations to strings.
-
implicit
def
stringToView(s: String): StringView
Convert string to iterable via view.
Convert string to iterable via view. Lower priority than StringOps
- Definition Classes
- LowPriority
- object IndexedView
- object Iterator
- object Seq
- object Set
-
object
View
This object reifies operations on views as case classes