fork(1) download
  1. import Function.unlift
  2.  
  3. case class T(property: String)
  4.  
  5. object Main extends App {
  6. val someIterator = Seq(T("a"), T("b"), T("b"), T("a"), T("b"), T("a")).toIterator
  7.  
  8. var foo = 0
  9. val xs = someIterator.map(_.property).collect(unlift {
  10. case "a" => foo += 1; None
  11. case "b" => Some("current foo" + foo)
  12. })
  13.  
  14. println(xs.toList)
  15. }
Success #stdin #stdout 0.37s 322240KB
stdin
Standard input is empty
stdout
List(current foo1, current foo1, current foo2)