forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scala#73 from scala/hierarchy
Flesh out the mutable type hierarchy
- Loading branch information
Showing
8 changed files
with
193 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
package strawman.collection.mutable | ||
|
||
import strawman.collection | ||
import strawman.collection.IterableFactory | ||
import strawman.collection.{IterableFactory, IterableOnce} | ||
|
||
trait Iterable[A] extends collection.Iterable[A] | ||
with collection.IterableOps[A, Iterable, Iterable[A]] | ||
import scala.Boolean | ||
|
||
trait Iterable[A] | ||
extends collection.Iterable[A] | ||
with IterableOps[A, Iterable, Iterable[A]] { | ||
|
||
def mapInPlace(f: A => A): this.type | ||
|
||
} | ||
|
||
trait IterableOps[A, +CC[X], +C] | ||
extends collection.IterableOps[A, CC, C] | ||
|
||
object Iterable | ||
extends IterableFactory.Delegate[Iterable](ArrayBuffer) | ||
|
||
trait GrowableIterable[A] | ||
extends Iterable[A] | ||
with Growable[A] { | ||
|
||
def flatMapInPlace(f: A => IterableOnce[A]): this.type | ||
|
||
def filterInPlace(p: A => Boolean): this.type | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/scala/strawman/collection/mutable/Shrinkable.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package strawman | ||
package collection.mutable | ||
|
||
import scala.annotation.tailrec | ||
|
||
import collection.toNewSeq | ||
import scala.{`inline`, Unit} | ||
|
||
/** This trait forms part of collections that can be reduced | ||
* using a `-=` operator. | ||
* | ||
* @author Martin Odersky | ||
* @version 2.8 | ||
* @since 2.8 | ||
* @define coll shrinkable collection | ||
* @define Coll `Shrinkable` | ||
*/ | ||
trait Shrinkable[-A] { | ||
|
||
/** Removes a single element from this $coll. | ||
* | ||
* @param elem the element to remove. | ||
* @return the $coll itself | ||
*/ | ||
def subtract(elem: A): this.type | ||
|
||
/** Alias for `subtract` */ | ||
@`inline` final def -= (elem: A): this.type = subtract(elem) | ||
|
||
/** Removes two or more elements from this $coll. | ||
* | ||
* @param elem1 the first element to remove. | ||
* @param elem2 the second element to remove. | ||
* @param elems the remaining elements to remove. | ||
* @return the $coll itself | ||
*/ | ||
def subtract(elem1: A, elem2: A, elems: A*): this.type = { | ||
this -= elem1 | ||
this -= elem2 | ||
this --= elems.toStrawman | ||
} | ||
|
||
/** Alias for `subtract` */ | ||
@`inline` final def -= (elem1: A, elem2: A, elems: A*): this.type = subtract(elem1, elem2, elems: _*) | ||
|
||
/** Removes all elements produced by an iterator from this $coll. | ||
* | ||
* @param xs the iterator producing the elements to remove. | ||
* @return the $coll itself | ||
*/ | ||
def subtractAll(xs: collection.IterableOnce[A]): this.type = { | ||
@tailrec def loop(xs: collection.LinearSeq[A]): Unit = { | ||
if (xs.nonEmpty) { | ||
subtract(xs.head) | ||
loop(xs.tail) | ||
} | ||
} | ||
xs match { | ||
case xs: collection.LinearSeq[A] => loop(xs) | ||
case xs => xs.iterator().foreach(subtract) | ||
} | ||
this | ||
} | ||
|
||
/** Alias for `subtractAll` */ | ||
@`inline` final def --= (xs: collection.IterableOnce[A]): this.type = subtractAll(xs) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters