forked from scala/scala3
-
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.
Add an
empty
operation to all collection instances
This will allow us to experiment with a different desugaring of `for` expressions, as described in scala#2573.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
object collectionsEmpty { | ||
|
||
locally { | ||
val xs1 = List(1, 2, 3) | ||
val xs2 = xs1.empty | ||
val xs3: List[Int] = xs2 | ||
} | ||
|
||
locally { | ||
val xs1 = Array(1, 2, 3) | ||
val xs2 = xs1.empty | ||
val xs3: Array[Int] = xs2 | ||
} | ||
|
||
locally { | ||
val xs1 = Set(1, 2, 3) | ||
val xs2 = xs1.empty | ||
val xs3: Set[Int] = xs2 | ||
} | ||
|
||
locally { | ||
val xs1 = "foo" | ||
val xs2 = xs1.empty | ||
val xs3: String = xs2 | ||
} | ||
|
||
// Commented because there is no IsTraversableLike[Range] instance | ||
// locally { | ||
// val xs1 = 1 to 3 | ||
// val xs2 = xs1.empty | ||
// val xs3: IndexedSeq[Int] = xs2 | ||
// } | ||
|
||
locally { | ||
val xs1 = Iterable(1, 2, 3) | ||
val xs2 = xs1.empty | ||
val xs3: Iterable[Int] = xs2 | ||
} | ||
|
||
} |