Scala Library: scala.collection.mutable.MutableList
scala.collection.mutable.MutableList
object MutableList extends SeqFactory[MutableList] with SerializableType Members
type Coll = MutableList[_]
The underlying collection type with unknown element type
- Attributes
- protected[this]
- Definition Classes
- GenericCompanion
class GenericCanBuildFrom[A] extends CanBuildFrom[CC[_], A, CC[A]]
A generic implementation of the CanBuildFrom trait, which forwards all calls
to apply(from) to the genericBuilder method of collection from , and which
forwards all calls of apply() to the newBuilder method of this factory.
- Definition Classes
- GenTraversableFactory
Value Members From scala.collection.generic.GenTraversableFactory
def ReusableCBF: GenericCanBuildFrom[Nothing]
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def concat[A](xss: collection.Traversable[A]*): MutableList[A]
Concatenates all argument collections into a single collection.
- xss
- the collections that are to be concatenated.
- returns
- the concatenation of all the collections.
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def fill[A](n: Int)(elem: ⇒ A): MutableList[A]
Produces a collection containing the results of some element computation a number of times.
- n
- the number of elements contained in the collection.
- elem
- the element computation
- returns
- A collection that contains the results of
nevaluations ofelem.
- A collection that contains the results of
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def fill[A](n1: Int, n2: Int)(elem: ⇒ A): MutableList[MutableList[A]]
Produces a two-dimensional collection containing the results of some element computation a number of times.
- n1
- the number of elements in the 1st dimension
- n2
- the number of elements in the 2nd dimension
- elem
- the element computation
- returns
- A collection that contains the results of
n1 x n2evaluations ofelem.
- A collection that contains the results of
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def fill[A](n1: Int, n2: Int, n3: Int)(elem: ⇒ A): MutableList[MutableList[MutableList[A]]]
Produces a three-dimensional collection containing the results of some element computation a number of times.
- n1
- the number of elements in the 1st dimension
- n2
- the number of elements in the 2nd dimension
- n3
- the number of elements in the 3nd dimension
- elem
- the element computation
- returns
- A collection that contains the results of
n1 x n2 x n3evaluations ofelem.
- A collection that contains the results of
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def fill[A](n1: Int, n2: Int, n3: Int, n4: Int)(elem: ⇒ A): MutableList[MutableList[MutableList[MutableList[A]]]]
Produces a four-dimensional collection containing the results of some element computation a number of times.
- n1
- the number of elements in the 1st dimension
- n2
- the number of elements in the 2nd dimension
- n3
- the number of elements in the 3nd dimension
- n4
- the number of elements in the 4th dimension
- elem
- the element computation
- returns
- A collection that contains the results of
n1 x n2 x n3 x n4evaluations ofelem.
- A collection that contains the results of
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def fill[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: ⇒ A): MutableList[MutableList[MutableList[MutableList[MutableList[A]]]]]
Produces a five-dimensional collection containing the results of some element computation a number of times.
- n1
- the number of elements in the 1st dimension
- n2
- the number of elements in the 2nd dimension
- n3
- the number of elements in the 3nd dimension
- n4
- the number of elements in the 4th dimension
- n5
- the number of elements in the 5th dimension
- elem
- the element computation
- returns
- A collection that contains the results of
n1 x n2 x n3 x n4 x n5evaluations ofelem.
- A collection that contains the results of
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def iterate[A](start: A, len: Int)(f: (A) ⇒ A): MutableList[A]
Produces a collection containing repeated applications of a function to a start value.
- start
- the start value of the collection
- len
- the number of elements contained inthe collection
- f
- the function that’s repeatedly applied
- returns
- a collection with
lenvalues in the sequencestart, f(start), f(f(start)), ...
- a collection with
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def range[T](start: T, end: T)(implicit arg0: Integral[T]): MutableList[T]
Produces a collection containing a sequence of increasing of integers.
- start
- the first element of the collection
- end
- the end value of the collection (the first value NOT contained)
- returns
- a collection with values
start, start + 1, ..., end - 1
- a collection with values
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def range[T](start: T, end: T, step: T)(implicit arg0: Integral[T]): MutableList[T]
Produces a collection containing equally spaced values in some integer interval.
- start
- the start value of the collection
- end
- the end value of the collection (the first value NOT contained)
- step
- the difference between successive elements of the collection (must be positive or negative)
- returns
- a collection with values
start, start + step, ...up to, but excludingend
- a collection with values
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def tabulate[A](n: Int)(f: (Int) ⇒ A): MutableList[A]
Produces a collection containing values of a given function over a range of integer values starting from 0.
- n
- The number of elements in the collection
- f
- The function computing element values
- returns
- A collection consisting of elements
f(0), ..., f(n -1)
- A collection consisting of elements
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def tabulate[A](n1: Int, n2: Int)(f: (Int, Int) ⇒ A): MutableList[MutableList[A]]
Produces a two-dimensional collection containing values of a given function over ranges of integer values starting from 0.
- n1
- the number of elements in the 1st dimension
- n2
- the number of elements in the 2nd dimension
- f
- The function computing element values
- returns
- A collection consisting of elements
f(i1, i2)for0 <= i1 < n1and0 <= i2 < n2.
- A collection consisting of elements
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def tabulate[A](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) ⇒ A): MutableList[MutableList[MutableList[A]]]
Produces a three-dimensional collection containing values of a given function over ranges of integer values starting from 0.
- n1
- the number of elements in the 1st dimension
- n2
- the number of elements in the 2nd dimension
- n3
- the number of elements in the 3nd dimension
- f
- The function computing element values
- returns
- A collection consisting of elements
f(i1, i2, i3)for0 <= i1 < n1,0 <= i2 < n2, and0 <= i3 < n3.
- A collection consisting of elements
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def tabulate[A](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) ⇒ A): MutableList[MutableList[MutableList[MutableList[A]]]]
Produces a four-dimensional collection containing values of a given function over ranges of integer values starting from 0.
- n1
- the number of elements in the 1st dimension
- n2
- the number of elements in the 2nd dimension
- n3
- the number of elements in the 3nd dimension
- n4
- the number of elements in the 4th dimension
- f
- The function computing element values
- returns
- A collection consisting of elements
f(i1, i2, i3, i4)for0 <= i1 < n1,0 <= i2 < n2,0 <= i3 < n3, and0 <= i4 < n4.
- A collection consisting of elements
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
def tabulate[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) ⇒ A): MutableList[MutableList[MutableList[MutableList[MutableList[A]]]]]
Produces a five-dimensional collection containing values of a given function over ranges of integer values starting from 0.
- n1
- the number of elements in the 1st dimension
- n2
- the number of elements in the 2nd dimension
- n3
- the number of elements in the 3nd dimension
- n4
- the number of elements in the 4th dimension
- n5
- the number of elements in the 5th dimension
- f
- The function computing element values
- returns
- A collection consisting of elements
f(i1, i2, i3, i4, i5)for0 <= i1 < n1,0 <= i2 < n2,0 <= i3 < n3,0 <= i4 < n4, and0 <= i5 < n5.
- A collection consisting of elements
- Definition Classes
- GenTraversableFactory
(defined at scala.collection.generic.GenTraversableFactory)
Value Members From scala.collection.generic.GenericCompanion
def apply[A](elems: A*): MutableList[A]
Creates a collection with the specified elements.
- A
- the type of the collection’s elements
- elems
- the elements of the created collection
- returns
- a new collection with elements
elems
- a new collection with elements
- Definition Classes
- GenericCompanion
(defined at scala.collection.generic.GenericCompanion)
def empty[A]: MutableList[A]
An empty collection of type CC[A]
- A
- the type of the collection’s elements
- Definition Classes
- GenericCompanion
(defined at scala.collection.generic.GenericCompanion)
Value Members From scala.collection.generic.SeqFactory
def unapplySeq[A](x: MutableList[A]): Some[MutableList[A]]
This method is called in a pattern match { case Seq(…) => }.
- x
- the selector value
- returns
- sequence wrapped in an option, if this is a Seq, otherwise none
- Definition Classes
- SeqFactory
(defined at scala.collection.generic.SeqFactory)
Value Members From scala.collection.mutable.MutableList
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, MutableList[A]]
(defined at scala.collection.mutable.MutableList)
def newBuilder[A]: Builder[A, MutableList[A]]
The default builder for Traversable objects.
- A
- the type of the collection’s elements
- Definition Classes
- MutableList → GenericCompanion (defined at scala.collection.mutable.MutableList)
Full Source:
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala
package collection
package mutable
import generic._
import immutable.List
/**
* This class is used internally to represent mutable lists. It is the
* basis for the implementation of the class `Queue`.
*
* @author Matthias Zenger
* @author Martin Odersky
* @version 2.8
* @since 1
* @define Coll `mutable.MutableList`
* @define coll mutable list
* @see [[http://docs.scala-lang.org/overviews/collections/concrete-mutable-collection-classes.html#mutable_lists "Scala's Collection Library overview"]]
* section on `Mutable Lists` for more information.
*/
@SerialVersionUID(5938451523372603072L)
class MutableList[A]
extends AbstractSeq[A]
with LinearSeq[A]
with LinearSeqOptimized[A, MutableList[A]]
with GenericTraversableTemplate[A, MutableList]
with Builder[A, MutableList[A]]
with Serializable
{
override def companion: GenericCompanion[MutableList] = MutableList
override protected[this] def newBuilder: Builder[A, MutableList[A]] = new MutableList[A]
protected var first0: LinkedList[A] = new LinkedList[A]
protected var last0: LinkedList[A] = first0
protected var len: Int = 0
def toQueue = new Queue(first0, last0, len)
/** Is the list empty?
*/
override def isEmpty = len == 0
/** Returns the first element in this list
*/
override def head: A = if (nonEmpty) first0.head else throw new NoSuchElementException
/** Returns the rest of this list
*/
override def tail: MutableList[A] = {
val tl = new MutableList[A]
tailImpl(tl)
tl
}
protected final def tailImpl(tl: MutableList[A]) {
require(nonEmpty, "tail of empty list")
tl.first0 = first0.tail
tl.len = len - 1
tl.last0 = if (tl.len == 0) tl.first0 else last0
}
/** Prepends a single element to this list. This operation takes constant
* time.
* @param elem the element to prepend.
* @return this $coll.
*/
def +=: (elem: A): this.type = { prependElem(elem); this }
/** Returns the length of this list.
*/
override def length: Int = len
/** Returns the `n`-th element of this list.
* @throws IndexOutOfBoundsException if index does not exist.
*/
override def apply(n: Int): A = first0.apply(n)
/** Updates the `n`-th element of this list to a new value.
* @throws IndexOutOfBoundsException if index does not exist.
*/
def update(n: Int, x: A): Unit = first0.update(n, x)
/** Returns the `n`-th element of this list or `None`
* if index does not exist.
*/
def get(n: Int): Option[A] = first0.get(n)
protected def prependElem(elem: A) {
first0 = new LinkedList[A](elem, first0)
if (len == 0) last0 = first0
len = len + 1
}
protected def appendElem(elem: A) {
if (len == 0) {
prependElem(elem)
} else {
last0.next = new LinkedList[A]
last0 = last0.next
last0.elem = elem
last0.next = new LinkedList[A] // for performance, use sentinel `object` instead?
len = len + 1
}
}
/** Returns an iterator over up to `length` elements of this list.
*/
override def iterator: Iterator[A] = if (isEmpty) Iterator.empty else
new AbstractIterator[A] {
var elems = first0
var count = len
def hasNext = count > 0 && elems.nonEmpty
def next() = {
if (!hasNext) throw new NoSuchElementException
count = count - 1
val e = elems.elem
elems = if (count == 0) null else elems.next
e
}
}
override def last = {
if (isEmpty) throw new NoSuchElementException("MutableList.empty.last")
last0.elem
}
/** Returns an instance of [[scala.List]] containing the same
* sequence of elements.
*/
override def toList: List[A] = first0.toList
/** Returns the current list of elements as a linked List
* sequence of elements.
*/
private[mutable] def toLinkedList: LinkedList[A] = first0
/** Appends a single element to this buffer. This takes constant time.
*
* @param elem the element to append.
*/
def +=(elem: A): this.type = { appendElem(elem); this }
def clear() {
first0 = new LinkedList[A]
last0 = first0
len = 0
}
def result = this
override def clone(): MutableList[A] = {
val bf = newBuilder
bf ++= seq
bf.result()
}
}
object MutableList extends SeqFactory[MutableList] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, MutableList[A]] =
ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
def newBuilder[A]: Builder[A, MutableList[A]] = new MutableList[A]
}Interested in Scala?
I send out weekly, personalized emails with articles and conference talks.
Subscribe now.