diff options
Diffstat (limited to 'src/library/scalax/collection/generic/covariant')
8 files changed, 140 insertions, 0 deletions
diff --git a/src/library/scalax/collection/generic/covariant/IterableFactory.scala b/src/library/scalax/collection/generic/covariant/IterableFactory.scala new file mode 100755 index 0000000000..67445f54d9 --- /dev/null +++ b/src/library/scalax/collection/generic/covariant/IterableFactory.scala @@ -0,0 +1,14 @@ +package scalax.collection.generic.covariant + +trait IterableFactory[CC[+A] <: Iterable[A]] extends generic.IterableFactory[CC] { + + /** The empty collection of type CC */ + val empty: CC[Nothing] + + override protected def newBuilder[A]: Builder[CC, A] = + empty.newBuilder[A].asInstanceOf[Builder[CC, A]] + + /** Create CC collection of specified elements */ + override def apply[A](args: A*): CC[A] = + (empty ++ args.asInstanceOf[Iterable[A]]).asInstanceOf[CC[A]] // !!! +} diff --git a/src/library/scalax/collection/generic/covariant/IterableTemplate.scala b/src/library/scalax/collection/generic/covariant/IterableTemplate.scala new file mode 100755 index 0000000000..41155a5ad5 --- /dev/null +++ b/src/library/scalax/collection/generic/covariant/IterableTemplate.scala @@ -0,0 +1,29 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2008, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Iterable.scala 15188 2008-05-24 15:01:02Z stepancheg $ + + +package scalax.collection.generic.covariant + +import annotation.unchecked.uncheckedVariance + +/** Collection classes mixing in this class provide a method + * <code>elements</code> which returns an iterator over all the + * elements contained in the collection. + * + * @note If a collection has a known <code>size</code>, it should also sub-type <code>Collection</code>. + * Only potentially unbounded collections should directly sub-class <code>Iterable</code>. + * @author Matthias Zenger + * @version 1.1, 04/02/2004 + */ +trait IterableTemplate[+CC[+B] <: IterableTemplate[CC, B] with Iterable[B], +A] + extends generic.IterableTemplate[CC, A @uncheckedVariance] { self /*: CC[A]*/ => } + +// !!! todo: explain why @uncheckedVariance is justified here. + diff --git a/src/library/scalax/collection/generic/covariant/IterableView.scala b/src/library/scalax/collection/generic/covariant/IterableView.scala new file mode 100755 index 0000000000..7ccad07405 --- /dev/null +++ b/src/library/scalax/collection/generic/covariant/IterableView.scala @@ -0,0 +1,21 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2008, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Iterable.scala 15188 2008-05-24 15:01:02Z stepancheg $ + +package scalax.collection.generic.covariant + +import annotation.unchecked.uncheckedVariance + +/** A non-strict projection of an iterable. + * @author Sean McDirmid + * @author Martin Odersky + * @note this should really be a virtual class of SequenceFactory + */ +trait IterableView[+UC[+B] <: Iterable[B], +A] + extends generic.IterableView[UC, A @uncheckedVariance] diff --git a/src/library/scalax/collection/generic/covariant/OrderedIterableTemplate.scala b/src/library/scalax/collection/generic/covariant/OrderedIterableTemplate.scala new file mode 100755 index 0000000000..449bac9cfc --- /dev/null +++ b/src/library/scalax/collection/generic/covariant/OrderedIterableTemplate.scala @@ -0,0 +1,17 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2008, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Iterable.scala 15188 2008-05-24 15:01:02Z stepancheg $ + + +package scalax.collection.generic.covariant + +import annotation.unchecked.uncheckedVariance + +trait OrderedIterableTemplate[+CC[+B] <: OrderedIterableTemplate[CC, B] with OrderedIterable[B], +A] + extends generic.OrderedIterableTemplate[CC, A @uncheckedVariance] {self /*: CC[A]*/ => } diff --git a/src/library/scalax/collection/generic/covariant/SequenceFactory.scala b/src/library/scalax/collection/generic/covariant/SequenceFactory.scala new file mode 100755 index 0000000000..49a6e685fa --- /dev/null +++ b/src/library/scalax/collection/generic/covariant/SequenceFactory.scala @@ -0,0 +1,3 @@ +package scalax.collection.generic.covariant + +trait SequenceFactory[CC[+A] <: Sequence[A]] extends IterableFactory[CC] with generic.SequenceFactory[CC] diff --git a/src/library/scalax/collection/generic/covariant/SequenceTemplate.scala b/src/library/scalax/collection/generic/covariant/SequenceTemplate.scala new file mode 100755 index 0000000000..958e73cd47 --- /dev/null +++ b/src/library/scalax/collection/generic/covariant/SequenceTemplate.scala @@ -0,0 +1,17 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2008, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Sequence.scala 16092 2008-09-12 10:37:06Z nielsen $ + + +package scalax.collection.generic.covariant + +import annotation.unchecked.uncheckedVariance + +trait SequenceTemplate[+CC[+B] <: SequenceTemplate[CC, B] with Sequence[B], +A] + extends generic.SequenceTemplate[CC, A @uncheckedVariance] {self /*: CC[A]*/ => } diff --git a/src/library/scalax/collection/generic/covariant/SequenceView.scala b/src/library/scalax/collection/generic/covariant/SequenceView.scala new file mode 100755 index 0000000000..cfcf9d4a25 --- /dev/null +++ b/src/library/scalax/collection/generic/covariant/SequenceView.scala @@ -0,0 +1,22 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2008, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Sequence.scala 16092 2008-09-12 10:37:06Z nielsen $ + + +package scalax.collection.generic.covariant + +import annotation.unchecked.uncheckedVariance + +/** A non-strict projection of an iterable. + * @author Sean McDirmid + * @author Martin Odersky + * @note this should really be a virtual class of SequenceFactory + */ +trait SequenceView[+UC[+B] <: Sequence[B], +A] + extends IterableView[UC, A] with generic.SequenceView[UC, A @uncheckedVariance] diff --git a/src/library/scalax/collection/generic/covariant/VectorTemplate.scala b/src/library/scalax/collection/generic/covariant/VectorTemplate.scala new file mode 100644 index 0000000000..1f75c68e82 --- /dev/null +++ b/src/library/scalax/collection/generic/covariant/VectorTemplate.scala @@ -0,0 +1,17 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2008, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: Sequence.scala 16092 2008-09-12 10:37:06Z nielsen $ + + +package scalax.collection.generic.covariant + +import annotation.unchecked.uncheckedVariance + +trait VectorTemplate[+CC[+B] <: VectorTemplate[CC, B] with Vector[B], +A] + extends generic.VectorTemplate[CC, A @uncheckedVariance] {self /*: CC[A]*/ => } |