Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An unmodifiable [List] view of another List. | 8 * An unmodifiable [List] view of another List. |
| 9 * | 9 * |
| 10 * The source of the elements may be a [List] or any [Iterable] with | 10 * The source of the elements may be a [List] or any [Iterable] with |
| 11 * efficient [Iterable.length] and [Iterable.elementAt]. | 11 * efficient [Iterable.length] and [Iterable.elementAt]. |
| 12 */ | 12 */ |
| 13 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { | 13 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { |
| 14 final Iterable<E> _source; | 14 final Iterable<E> _source; |
| 15 | |
| 16 /** | |
| 17 * Returns a view of [source] that's guaranteed to be unmodifiable. | |
| 18 * | |
| 19 * If [source] already extends [UnmodifiableListBase] or | |
| 20 * [UnmodifiableListView], this avoids re-wrapping it. | |
|
Lasse Reichstein Nielsen
2015/08/27 07:59:04
-> , it is returned without re-wrapping it.
(to s
nweiz
2015/08/27 19:25:37
Done.
| |
| 21 */ | |
| 22 static List ensure(Iterable source) => | |
|
Lasse Reichstein Nielsen
2015/08/27 07:59:04
I'm not sure I like the name. It's too ... non-des
Lasse Reichstein Nielsen
2015/08/27 07:59:04
Move static method below constructor.
nweiz
2015/08/27 19:25:37
My intention was that it would be clear that it wo
sra1
2015/08/27 20:24:52
How does this type-check in DDC?
nweiz
2015/08/28 00:41:29
I'm not sure how to test that... "dartanalyzer --s
Lasse Reichstein Nielsen
2015/08/31 09:08:23
UmodifiableListView.unmodifiable isn't very clear
Bob Nystrom
2015/08/31 20:42:45
Drive-by comment! A 39-character method name is pr
| |
| 23 source is UnmodifiableListBase | |
|
Lasse Reichstein Nielsen
2015/08/27 07:59:04
This is slightly dangerous because someone might h
sra1
2015/10/06 19:19:22
I don't think it is clear because it is not clear
| |
| 24 ? source | |
| 25 : new UnmodifiableListView(source); | |
| 26 | |
| 15 /** Create an unmodifiable list backed by [source]. */ | 27 /** Create an unmodifiable list backed by [source]. */ |
| 16 UnmodifiableListView(Iterable<E> source) : _source = source; | 28 UnmodifiableListView(Iterable<E> source) : _source = source; |
|
sra1
2015/10/06 19:19:22
Question: why is source Iterable?
Lasse Reichstein Nielsen
2015/10/07 07:40:40
Because the UnmodifiableListView is also a way to
| |
| 17 int get length => _source.length; | 29 int get length => _source.length; |
| 18 E operator[](int index) => _source.elementAt(index); | 30 E operator[](int index) => _source.elementAt(index); |
| 19 } | 31 } |
| OLD | NEW |