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#273 from scala/wip/compat-methods
A collection of smaller changes from my integration branch
- Loading branch information
Showing
44 changed files
with
1,178 additions
and
102 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
25 changes: 25 additions & 0 deletions
25
collections/src/main/scala/strawman/collection/BufferedIterator.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,25 @@ | ||
package strawman.collection | ||
|
||
import scala.{Option, Some, None} | ||
|
||
/** Buffered iterators are iterators which provide a method `head` | ||
* that inspects the next element without discarding it. | ||
* | ||
* @author Martin Odersky | ||
* @version 2.8 | ||
* @since 2.8 | ||
*/ | ||
trait BufferedIterator[+A] extends Iterator[A] { | ||
|
||
/** Returns next element of iterator without advancing beyond it. | ||
*/ | ||
def head: A | ||
|
||
/** Returns an option of the next element of an iterator without advancing beyond it. | ||
* @return the next element of this iterator if it has a next element | ||
* `None` if it does not | ||
*/ | ||
def headOption : Option[A] = if (hasNext) Some(head) else None | ||
|
||
override def buffered: this.type = this | ||
} |
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
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
63 changes: 62 additions & 1 deletion
63
collections/src/main/scala/strawman/collection/IterableOnce.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 |
---|---|---|
@@ -1,11 +1,72 @@ | ||
package strawman | ||
package collection | ||
|
||
import scala.{Any, Int} | ||
import scala.{Any, Int, Unit, deprecated, `inline`, AnyVal, Boolean, Array, Option} | ||
import scala.Predef.String | ||
import scala.language.implicitConversions | ||
import scala.reflect.ClassTag | ||
|
||
trait IterableOnce[+A] extends Any { | ||
/** Iterator can be used only once */ | ||
def iterator(): Iterator[A] | ||
|
||
def knownSize: Int | ||
} | ||
|
||
final class IterableOnceExtensionMethods[A](private val it: IterableOnce[A]) extends AnyVal { | ||
@deprecated("Use .iterator().foreach(...) instead of .foreach(...) on IterableOnce", "2.13.0") | ||
@`inline` def foreach[U](f: A => U): Unit = it match { | ||
case it: Iterable[_] => it.asInstanceOf[Iterable[A]].foreach(f) | ||
case _ => it.iterator().foreach(f) | ||
} | ||
|
||
@deprecated("Use ArrayBuffer.fromIterable(it) instead of it.toBuffer on Iterable (wrap Iterators with View.fromIterator first)", "2.13.0") | ||
def toBuffer[B >: A]: mutable.Buffer[B] = it match { | ||
case it: Iterable[_] => mutable.ArrayBuffer.from(it) | ||
case _ => mutable.ArrayBuffer.from(View.fromIteratorProvider(() => it.iterator())) | ||
} | ||
|
||
@deprecated("Use ArrayBuffer.fromIterable(it).toArray instead of it.toArray on Iterable (wrap Iterators with View.fromIterator first)", "2.13.0") | ||
def toArray[B >: A: ClassTag]: Array[B] = it match { | ||
case it: Iterable[_] => it.asInstanceOf[Iterable[B]].toArray[B] | ||
case _ => mutable.ArrayBuffer.from(View.fromIteratorProvider(() => it.iterator())).toArray | ||
} | ||
|
||
@deprecated("Use List.fromIterable(it) instead of it.toList on Iterable (wrap Iterators with View.fromIterator first)", "2.13.0") | ||
def toList[B >: A]: immutable.List[B] = it match { | ||
case it: Iterable[_] => immutable.List.from(it.asInstanceOf[Iterable[B]]) | ||
case _ => immutable.List.from(View.fromIteratorProvider(() => it.iterator())) | ||
} | ||
|
||
@deprecated("Use .iterator().isEmpty instead of .isEmpty on IterableOnce", "2.13.0") | ||
def isEmpty: Boolean = it match { | ||
case it: Iterable[_] => it.isEmpty | ||
case _ => it.iterator().isEmpty | ||
} | ||
|
||
@deprecated("Use .iterator().mkString instead of .mkString on IterableOnce", "2.13.0") | ||
def mkString(start: String, sep: String, end: String): String = it match { | ||
case it: Iterable[_] => it.mkString(start, sep, end) | ||
case _ => it.iterator().mkString(start, sep, end) | ||
} | ||
|
||
@deprecated("Use .iterator().mkString instead of .mkString on IterableOnce", "2.13.0") | ||
def mkString(sep: String): String = it match { | ||
case it: Iterable[_] => it.mkString(sep) | ||
case _ => it.iterator().mkString(sep) | ||
} | ||
|
||
@deprecated("Use .iterator().mkString instead of .mkString on IterableOnce", "2.13.0") | ||
def mkString: String = it match { | ||
case it: Iterable[_] => it.mkString | ||
case _ => it.iterator().mkString | ||
} | ||
|
||
@deprecated("Use .iterator().find instead of .find on IterableOnce", "2.13.0") | ||
def find(p: A => Boolean): Option[A] = it.iterator().find(p) | ||
} | ||
|
||
object IterableOnce { | ||
@`inline` implicit def iterableOnceExtensionMethods[A](it: IterableOnce[A]): IterableOnceExtensionMethods[A] = | ||
new IterableOnceExtensionMethods[A](it) | ||
} |
Oops, something went wrong.