You can do this a little better by using the |> operator from Scalaz.
scala> val captures = Vector("Hello", "World") captures: scala.collection.immutable.Vector[java.lang.String] = Vector(Hello, World) scala> val (a, b) = captures |> { x => (x(0), x(1)) } a: java.lang.String = Hello b: java.lang.String = World
If you do not want to use Scalaz, you can define |> yourself, as shown below:
scala> class AW[A](a: A) { | def |>[B](f: A => B): B = f(a) | } defined class AW scala> implicit def aW[A](a: A): AW[A] = new AW(a) aW: [A](a: A)AW[A]
EDIT:
Or, something like the @ziggystar suggestion:
scala> val Vector(a, b) = captures a: java.lang.String = Hello b: java.lang.String = World
You can make it more concise, as shown below:
scala> val S = Seq S: scala.collection.Seq.type = scala.collection.Seq$@157e63a scala> val S(a, b) = captures a: java.lang.String = Hello b: java.lang.String = World
source share