abstract class Parser[I, T] { def parse(ts: I): Set[(T, I)] def parse_all(ts: I) : Set[T] = for ((head, tail) <- parse(ts); if (tail.isEmpty)) yield head }