Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: sdk/lib/collection/collections.dart

Issue 1319783003: Add static ensure() methods to unmodifiable views. Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/collection/collections.dart
diff --git a/sdk/lib/collection/collections.dart b/sdk/lib/collection/collections.dart
index fb9a94b8832dcbfb685b08ca6d39ab0750444a8e..6f0d42692527977a809ca31c6bda463266fcd7a6 100644
--- a/sdk/lib/collection/collections.dart
+++ b/sdk/lib/collection/collections.dart
@@ -12,6 +12,18 @@ part of dart.collection;
*/
class UnmodifiableListView<E> extends UnmodifiableListBase<E> {
final Iterable<E> _source;
+
+ /**
+ * Returns a view of [source] that's guaranteed to be unmodifiable.
+ *
+ * If [source] already extends [UnmodifiableListBase] or
+ * [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.
+ */
+ 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
+ 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
+ ? source
+ : new UnmodifiableListView(source);
+
/** Create an unmodifiable list backed by [source]. */
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
int get length => _source.length;
« no previous file with comments | « CHANGELOG.md ('k') | sdk/lib/collection/maps.dart » ('j') | sdk/lib/collection/maps.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698