Advertisement
Guest User

List[A] => Int without using length

a guest
Mar 13th, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.36 KB | None | 0 0
  1. object tony {
  2.   println("Welcome to the Scala worksheet")       //> Welcome to the Scala worksheet
  3.  
  4.   def foo[A](l:List[A]):Int = {
  5.     l.zipWithIndex.indexWhere { pair => l.indexOf(pair._1) != pair._2 }
  6.   }                                               //> foo: [A](l: List[A])Int
  7.  
  8.   foo(List(1, 2, 3, 3, 4))                        //> res0: Int = 3
  9.  
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement