class Test def main is shared t as IList = for x in [1, 2, 3] get x assert t.count==3 assert t[0]==1 assert t[1]==2 assert t[2]==3 assert (for x as int in [1, 2, 3] get x) == [1, 2, 3] assert [1, 2, 3] == for x in [1, 2, 3] get x assert (for x in [1, 2, 3] get x*x) == [1, 4, 9] assert [1, 4, 9] == for x in [1, 2, 3] get x*x assert (for s as String in ['aa', 'bbbb', 'cccccc'] get s.length) == [2, 4, 6] assert [2, 4, 6] == for s in ['aa', 'bbbb', 'cccccc'] get s.length # with `where` t = for x in [1, 2, 3] where x<>2 get x assert t.count==2 assert t[0]==1 assert t[1]==3 # given a 'where' you can skip 'get' t = for x in [1, 2, 3] where x<>2 assert t.count==2 assert t[0]==1 assert t[1]==3 assert (for x in [1, 2, 3] where x<>2 get x) == [1, 3] assert (for x in [1, 2, 3] where x<>2) == [1, 3] assert [1, 3] == for x in [1, 2, 3] where x<>2 get x assert [1, 3] == for x in [1, 2, 3] where x<>2 assert (for x in [1, 2, 3] where x<>2 get x*x)==[1, 9] assert [1, 9] == for x in [1, 2, 3] where x<>2 get x*x assert (for s in ['aa', 'bbbb', 'cccccc'] where s<>'bbbb' get s.length) == [2, 6] assert [2, 6] == for s in ['aa', 'bbbb', 'cccccc'] where s<>'bbbb' get s.length # where with a non bool-typed expression stuff = 'aoeu asdf' words = for rawWord in stuff.split where rawWord.trim.length get rawWord.trim assert words == ['aoeu', 'asdf'] words = for word in words where word <> 'asdf' # assign for expr back to source variable assert words == ['aoeu'] # okay sneak in a non-generic for expr ie as System.Collections.IEnumerable = [1, 2, 3] assert [2, 4, 6] == for i in ie get 2*(i to int) assert [4, 6] == for i in ie where (i to int) > 1 get 2*(i to int)