You can do this with any Iterable using an iterator (which evaluates lazily - it's called elements in 2.7). Try it:
case class Foo(i: Int) { def bar = { println("Calling bar from Foo("+i+")") (if ((i%4)==0) "bar says "+i else null) } } val foos = List(Foo(1),Foo(2),Foo(3),Foo(4),Foo(5),Foo(6)) foos.iterator.map(_.bar).find(_!=null)
Rex kerr
source share