Created
May 21, 2013 07:19
-
-
Save minosiants/5618046 to your computer and use it in GitHub Desktop.
Find value in vector of vectors
This file contains hidden or 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
@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