コレクション内の要素のインデックスを見つけるエレガントな方法は何ですか? 今のところ、次のようなメソッドを実装しました。
def getIndexForValue[T] (value: T, collection: Iterable[T]): Option[Int] = {
val pair = collection.zipWithIndex.find(_._1 == value)
if (pair.isDefined) Some(pair.get._2) else None
}
よりエレガントな方法で書き直すことはできますか?ありがとう