Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_collection.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2006-2008 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import abstract_collection
18
19 class A
20 fun foo do 1.output
21 end
22
23 class G[E]
24 super Collection[E]
25
26 var a: E
27
28 redef fun iterator do return new I[E](self)
29 end
30
31 class I[E]
32 super Iterator[E]
33
34 var g: G[E]
35 var fini: Bool = false
36
37 redef fun next
38 do
39 fini = true
40 end
41
42 redef fun is_ok
43 do
44 return not fini
45 end
46
47 redef fun item
48 do
49 return g.a
50 end
51 end
52
53 class B
54 var a = new A
55 var g = new G[A](a)
56
57 fun bar
58 do
59 for x in g do x.foo
60 end
61 end
62
63 var b = new B
64 b.bar
65 for x in b.g do x.foo