Pimp my Library化。
#indexOfは既に存在するから別の名前にしないとimplicitが働かないな

implicit def toIndexedSeqWithBinarySearch[T <% Ordered[T]](xs: IndexedSeq[T]) = new {
def binarySearch(elem: Ordered[T]): Int = {
@scala.annotation.tailrec
def lambda(from: Int, to: Int): Option[Int] = (from + (to - from) / 2) match {
case i if to < from => None
case i if elem < xs(i) => lambda(from, i - 1)
case i if elem > xs(i) => lambda(i + 1, to)
case i => Some(i)
}
lambda(0, xs.length - 1).getOrElse(-1)
}
}

scala> Vector(1,2,3).binarySearch(2)
res2: Int = 2