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

Unified Diff: pkg/analysis_server/lib/src/collections.dart

Issue 629283002: Simplify conversion of empty lists to null. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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: pkg/analysis_server/lib/src/collections.dart
diff --git a/pkg/analysis_server/lib/src/collections.dart b/pkg/analysis_server/lib/src/collections.dart
index f85bc975cffdbe72a7cf396956b40879ec5cedc6..e49a0fe7f22f00cbd7557f38264eb6eda5c982ba 100644
--- a/pkg/analysis_server/lib/src/collections.dart
+++ b/pkg/analysis_server/lib/src/collections.dart
@@ -16,3 +16,17 @@ Iterable concat(Iterable<Iterable> iterables) => iterables.expand((x) => x);
* Returns the concatentation of the input iterables as a [List].
*/
List concatToList(Iterable<Iterable> iterables) => concat(iterables).toList();
+
+
+/**
+ * Returns the given [list] if it is not empty, or `null` otherwise.
+ */
+List nullIfEmpty(List list) {
+ if (list == null) {
+ return null;
+ }
+ if (list.isEmpty) {
+ return null;
+ }
+ return list;
+}

Powered by Google App Engine
This is Rietveld 408576698