Skip to content

Instantly share code, notes, and snippets.

@minosiants
Created May 21, 2013 07:19
Show Gist options
  • Save minosiants/5618046 to your computer and use it in GitHub Desktop.
Save minosiants/5618046 to your computer and use it in GitHub Desktop.
Find value in vector of vectors
@tailrec
def find[A](value:A, v:Vector[Vector[A]]):Option[A]={
v.head.find(_==value) match {
case Some(i) => Some(i)
case None if v.size==1 => None
case None => find(value,v.tail)
}
}
def find2[A](value:A, v:Vector[Vector[A]]):Option[A]={
v.collectFirst{Function.unlift{_.find(_==value)}}
}
val v=Vector(Vector(2,4,6,7,8,3),Vector(2,4,6,7,8,3),Vector(2,4,6,7,800,3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment