mofidied iterator program to test iterator collector and pattern matching