Skip to content

Commit 4036311

Browse files
committed
Add -> alias for Tuple2 to Predef
Allow users to pattern match on instances of `Tuple2` with the alternative syntax `key -> value`, in line with the existing alternative syntax for constructing a `Tuple2`.
1 parent 515f02f commit 4036311

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/src/scala/Predef.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ object Predef extends LowPriorityImplicits {
167167
/** @group aliases */
168168
val Set = immutable.Set
169169

170+
/**
171+
* Allows destructuring tuples with the same syntax as constructing them.
172+
*
173+
* @example {{{
174+
* val tup = "foobar" -> 3
175+
*
176+
* val c = tup match {
177+
* case str -> i => str.charAt(i)
178+
* }
179+
* }}}
180+
* @group aliases
181+
*/
182+
val -> = Tuple2
183+
170184
// Manifest types, companions, and incantations for summoning
171185
@annotation.implicitNotFound(msg = "No ClassManifest available for ${T}.")
172186
@deprecated("use `scala.reflect.ClassTag` instead", "2.10.0")

0 commit comments

Comments
 (0)