集合類別架構

Collection Base Classes Architecture

Overview

適用版本, 2.8

Scala Collection SVN, http://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/src/library/scala/collection





trait scala.collection.Traversable[+A]


SVN Code, http://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/src/library/scala/collection/Traversable.scala

Traversable, 能橫跨, 能越過, 可遍歷佚代

Traversable 類似 Java 中的被泛化的 Iterable, 位於 Scala 集合架構的最頂層.

David McIver gave me the idea of builders as implicit parameters and proposed Traversable as a generalization of Iterable.



trait scala.collection.Iterable


trait Iterable[+A]
extends Traversable[A] with TraversableClass[A, Iterable] with IterableTemplate[A, Iterable[A]]

A template trait for iterable collections.

Collection classes mixing in this trait provide a method iterator which returns an iterator over all the elements contained in the collection. They also provide a method newBuilder which creates a builder for collections of the same kind.

This trait implements Traversable's foreach method by stepping through all elements. Subclasses of Iterable should re-implement foreach with something more efficient, if possible.

This trait adds methods iterator, zip, zipAll, zipWithIndex, sameElements, takeRight, dropRight to the methods inherited from trait Traversable.

Author
Martin Odersky
Version
2.8
Direct Known Subclasses:
IterableProxy, JavaConversions.JIterableWrapper, JavaConversions.JCollectionWrapper,
MapSequenceSet,IterableForwarder, IterableViewTemplate, MapTemplate.DefaultValuesIterable,
IterableIterable, Directory, File, Process,Process.StreamedConsumer, Binders.Scope, MetaData
  • trait scala.collection.immutable.Iterable
  • trait scala.collection.mutable.Iterable
  • trait scala.collection.Map
  • trait.scala.collection.Sequence
  • trait.scala.collection.Set




Pakcages



scala.collection

All collection classes are now kept in a package scala.collection. This package has three subpackages:
mutable, immutable, and generic. Most collections exist in three forms, depending on their mutability.

scala.collection.immutable

確保不變性的集合, 並只能用於取得容器元素有關的操作, 而無法再改變容器的內容.

A collection in package scala.collection.immutable is guaranteed to be immutable for everyone.
That means one can rely on the fact that accessing the same collection value over time will always yield a collection with the same elements.


scala.collection.mutable

可變性的集合容器, 並提供完整的容器存取操作.

A collection in package scala.collection.mutable is known to have some operations that change the collection in place.




scala.collection.generic

The generic package contains building blocks for implementing various collections.





scala.collection.interface




scala.collection.script



For instance,
collection.Vector[T] is a superclass of both collection.immutable.Vector[T] and
collection.mutable.Vector[T]. Generally, the root collections in package scala.collection define
the same interface as the immutable collections, and the mutable collections in package
scala.collection.mutable typically add some destructive modification operations to this immutable
interface. The difference between root collections and immutable collections is that a user of an
immutable collection has a guarantee that nobody can mutate the collection, whereas users of root
collections have to assume modifications by others, even though they cannot do any modifications
themselves.


Comments