`withFilter` rocks when used as a flag & something like short circulating

u.go
2016-09-26T06:28:04Z

anyDuplicate.scala

| def anyDuplicate(arr: List[Int], k: Int): Boolean = {
| var any_duplicate = false
| val hs = mutable.HashSet[(Int, Int)]()
| arr.zipWithIndex
| .withFilter(_ => !any_duplicate)
| .map {
| case tp @ (e, idx) =>
| hs.find(_._1 == tp._1) match {
| case Some((d, idxD)) if (tp._2 - idxD <= k) =>
| any_duplicate = true // <-------- update flag
| case Some(_) => ()
| case None =>
| hs.add(tp)
| }
| }
| any_duplicate
| }