OLD | NEW |
1 // Copyright 2013 Google Inc. All Rights Reserved. | 1 // Copyright 2013 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 part of quiver.collection; | 15 part of quiver.collection; |
16 | 16 |
17 /** | 17 /// An implementation of [Iterable] that delegates all methods to another |
18 * An implementation of [Iterable] that delegates all methods to another | 18 /// [Iterable]. For instance you can create a FruitIterable like this : |
19 * [Iterable]. | 19 /// |
20 * For instance you can create a FruitIterable like this : | 20 /// class FruitIterable extends DelegatingIterable<Fruit> { |
21 * | 21 /// final Iterable<Fruit> _fruits = []; |
22 * class FruitIterable extends DelegatingIterable<Fruit> { | 22 /// |
23 * final Iterable<Fruit> _fruits = []; | 23 /// Iterable<Fruit> get delegate => _fruits; |
24 * | 24 /// |
25 * Iterable<Fruit> get delegate => _fruits; | 25 /// // custom methods |
26 * | 26 /// } |
27 * // custom methods | |
28 * } | |
29 */ | |
30 abstract class DelegatingIterable<E> implements Iterable<E> { | 27 abstract class DelegatingIterable<E> implements Iterable<E> { |
31 Iterable<E> get delegate; | 28 Iterable<E> get delegate; |
32 | 29 |
33 bool any(bool test(E element)) => delegate.any(test); | 30 bool any(bool test(E element)) => delegate.any(test); |
34 | 31 |
35 bool contains(Object element) => delegate.contains(element); | 32 bool contains(Object element) => delegate.contains(element); |
36 | 33 |
37 E elementAt(int index) => delegate.elementAt(index); | 34 E elementAt(int index) => delegate.elementAt(index); |
38 | 35 |
39 bool every(bool test(E element)) => delegate.every(test); | 36 bool every(bool test(E element)) => delegate.every(test); |
40 | 37 |
41 Iterable expand(Iterable f(E element)) => delegate.expand(f); | 38 Iterable<T> expand<T>(Iterable<T> f(E element)) => delegate.expand(f); |
42 | 39 |
43 E get first => delegate.first; | 40 E get first => delegate.first; |
44 | 41 |
45 E firstWhere(bool test(E element), {E orElse()}) => | 42 E firstWhere(bool test(E element), {E orElse()}) => |
46 delegate.firstWhere(test, orElse: orElse); | 43 delegate.firstWhere(test, orElse: orElse); |
47 | 44 |
48 fold(initialValue, combine(previousValue, E element)) => | 45 T fold<T>(T initialValue, T combine(T previousValue, E element)) => delegate |
49 delegate.fold(initialValue, combine); | 46 .fold(initialValue, combine); |
50 | 47 |
51 void forEach(void f(E element)) => delegate.forEach(f); | 48 void forEach(void f(E element)) => delegate.forEach(f); |
52 | 49 |
53 bool get isEmpty => delegate.isEmpty; | 50 bool get isEmpty => delegate.isEmpty; |
54 | 51 |
55 bool get isNotEmpty => delegate.isNotEmpty; | 52 bool get isNotEmpty => delegate.isNotEmpty; |
56 | 53 |
57 Iterator<E> get iterator => delegate.iterator; | 54 Iterator<E> get iterator => delegate.iterator; |
58 | 55 |
59 String join([String separator = ""]) => delegate.join(separator); | 56 String join([String separator = ""]) => delegate.join(separator); |
60 | 57 |
61 E get last => delegate.last; | 58 E get last => delegate.last; |
62 | 59 |
63 E lastWhere(bool test(E element), {E orElse()}) => | 60 E lastWhere(bool test(E element), {E orElse()}) => |
64 delegate.lastWhere(test, orElse: orElse); | 61 delegate.lastWhere(test, orElse: orElse); |
65 | 62 |
66 int get length => delegate.length; | 63 int get length => delegate.length; |
67 | 64 |
68 Iterable map(f(E element)) => delegate.map(f); | 65 Iterable<T> map<T>(T f(E e)) => delegate.map(f); |
69 | 66 |
70 E reduce(E combine(E value, E element)) => delegate.reduce(combine); | 67 E reduce(E combine(E value, E element)) => delegate.reduce(combine); |
71 | 68 |
72 E get single => delegate.single; | 69 E get single => delegate.single; |
73 | 70 |
74 E singleWhere(bool test(E element)) => delegate.singleWhere(test); | 71 E singleWhere(bool test(E element)) => delegate.singleWhere(test); |
75 | 72 |
76 Iterable<E> skip(int n) => delegate.skip(n); | 73 Iterable<E> skip(int n) => delegate.skip(n); |
77 | 74 |
78 Iterable<E> skipWhile(bool test(E value)) => delegate.skipWhile(test); | 75 Iterable<E> skipWhile(bool test(E value)) => delegate.skipWhile(test); |
79 | 76 |
80 Iterable<E> take(int n) => delegate.take(n); | 77 Iterable<E> take(int n) => delegate.take(n); |
81 | 78 |
82 Iterable<E> takeWhile(bool test(E value)) => delegate.takeWhile(test); | 79 Iterable<E> takeWhile(bool test(E value)) => delegate.takeWhile(test); |
83 | 80 |
84 List<E> toList({bool growable: true}) => delegate.toList(growable: growable); | 81 List<E> toList({bool growable: true}) => delegate.toList(growable: growable); |
85 | 82 |
86 Set<E> toSet() => delegate.toSet(); | 83 Set<E> toSet() => delegate.toSet(); |
87 | 84 |
88 Iterable<E> where(bool test(E element)) => delegate.where(test); | 85 Iterable<E> where(bool test(E element)) => delegate.where(test); |
89 } | 86 } |
OLD | NEW |