Question: I am searching a vector of vectors for a specific int.

```
  def searchVectors(i: Int, vectors: Vector[Vector[Int]]) = {
    val x = vectors.indexWhere(_.indexWhere(_ == i))
    val y = vectors(x).indexOf(y)
    (x, y)
  }

```

You can see I get the y twice. Firstly when computing x and then again when computing y.
Not good. How do I do it so I only compute y once?

Thanks

Answer: 
This bothered me too. You may have already thought of this, but if you are willing to violate the functional programming principle of immutable state etc. here is one possible approach:

```
val v = Vector(Vector(1,2,3), Vector(4, 5, 6))
var c: Int = -1
val r = v.indexWhere(r => {c = r.indexOf(6); c != -1})
(r, c)

```
Here's a easy-to-understand solution

```
def searchVectors(i: Int, vectors: Vector[Vector[Int]]): (Int, Int) = {
    val row = vectors.indexWhere(_.contains(i)) // Try to get index of vector containing element
    if (row > -1) (row, vectors(row).indexOf(i)) // (row, col)
    else (-1, -1)
}

```