Skip to content

Instantly share code, notes, and snippets.

@Yuichiroh
Last active July 21, 2017 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yuichiroh/33e7444b390be6142ede90632f648708 to your computer and use it in GitHub Desktop.
Save Yuichiroh/33e7444b390be6142ede90632f648708 to your computer and use it in GitHub Desktop.
argmax in Scala
implicit class ArgmaxColl[A, CC[X] <: Seq[X]](val coll: CC[A]) extends AnyVal {
def argmax(implicit o:Ordering[A]): Int = coll.indices.maxBy(coll)
}
val as = scala.util.Random.shuffle(1 to 10)
as.argmax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment