Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_iterator2.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 class ColIterable
16 fun iterator: MyIterator do return new MyIterator
17 end
18
19 class MyIterator
20 super Iterator[String]
21
22 var count = 0
23 redef fun is_ok do return count < 3
24 redef fun next do count += 1
25 redef fun item do return "Item{count}"
26 end
27
28 class MapIterable
29 fun iterator: MyMapIterator do return new MyMapIterator
30 end
31
32 class MyMapIterator
33 super MapIterator[String, String]
34
35 var count = 0
36 redef fun is_ok do return count < 3
37 redef fun next do count += 1
38 redef fun item do return "Item{count}"
39 redef fun key do return "Key{count}"
40 end
41
42 #ok
43 var col = new ColIterable
44 for v in col do print v
45
46 #ok
47 var map = new MapIterable
48 for k, v in map do print "{k}:{v}"
49