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.iterables; | 15 part of quiver.iterables; |
16 | 16 |
17 /** | 17 /// Returns the result of merging an [Iterable] of [Iterable]s, according to |
18 * Returns the result of merging an [Iterable] of [Iterable]s, according to | 18 /// the order specified by the [compare] function. This function assumes the |
19 * the order specified by the [compare] function. This function assumes the | 19 /// provided iterables are already sorted according to the provided [compare] |
20 * provided iterables are already sorted according to the provided [compare] | 20 /// function. It will not check for this condition or sort the iterables. |
21 * function. It will not check for this condition or sort the iterables. | 21 /// |
22 * | 22 /// The compare function must act as a [Comparator]. If [compare] is omitted, |
23 * The compare function must act as a [Comparator]. If [compare] is omitted, | 23 /// [Comparable.compare] is used. |
24 * [Comparable.compare] is used. | 24 /// |
25 * | 25 /// If any of the [iterables] contain null elements, an exception will be |
26 * If any of the [iterables] contain null elements, an exception will be | 26 /// thrown. |
27 * thrown. | |
28 */ | |
29 Iterable merge(Iterable<Iterable> iterables, | 27 Iterable merge(Iterable<Iterable> iterables, |
30 [Comparator compare = Comparable.compare]) => | 28 [Comparator compare = Comparable.compare]) => |
31 (iterables.isEmpty) ? const [] : new _Merge(iterables, compare); | 29 (iterables.isEmpty) ? const [] : new _Merge(iterables, compare); |
32 | 30 |
33 class _Merge extends IterableBase { | 31 class _Merge extends IterableBase { |
34 final Iterable<Iterable> _iterables; | 32 final Iterable<Iterable> _iterables; |
35 final Comparator _compare; | 33 final Comparator _compare; |
36 | 34 |
37 _Merge(this._iterables, this._compare); | 35 _Merge(this._iterables, this._compare); |
38 | 36 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 if (minIter == null) { | 78 if (minIter == null) { |
81 return false; | 79 return false; |
82 } | 80 } |
83 _current = minIter.current; | 81 _current = minIter.current; |
84 minIter.moveNext(); | 82 minIter.moveNext(); |
85 return true; | 83 return true; |
86 } | 84 } |
87 | 85 |
88 get current => _current; | 86 get current => _current; |
89 } | 87 } |
OLD | NEW |