From af1e8fc2ea6cca14c4fa78875ff9a95fa1f23bfe Mon Sep 17 00:00:00 2001
From: "lrn@google.com" <lrn@google.com>
Date: Thu, 31 Jan 2013 15:12:56 +0000
Subject: [PATCH] Reapply "Rename mappedBy to map."

This reverts commit r17907.

TBR.

Review URL: https://codereview.chromium.org//12090093

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@17918 260f80e4-7a28-3924-810f-c04153c831b5
---
 lib/src/command_lish.dart        |  2 +-
 lib/src/entrypoint.dart          |  6 +++---
 lib/src/hosted_source.dart       |  2 +-
 lib/src/io.dart                  |  8 ++++----
 lib/src/utils.dart               |  2 +-
 lib/src/validator.dart           |  6 +++---
 lib/src/validator/directory.dart |  2 +-
 lib/src/validator/lib.dart       |  2 +-
 lib/src/validator/license.dart   |  2 +-
 lib/src/validator/name.dart      |  2 +-
 lib/src/version.dart             |  2 +-
 lib/src/version_solver.dart      |  6 +++---
 test/command_line_config.dart    |  4 ++--
 test/test_pub.dart               | 16 ++++++++--------
 14 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/lib/src/command_lish.dart b/lib/src/command_lish.dart
index 59bfbbf4..81d896a9 100644
--- a/lib/src/command_lish.dart
+++ b/lib/src/command_lish.dart
@@ -128,7 +128,7 @@ class LishCommand extends PubCommand {
       }
 
       return listDir(rootDir, recursive: true).then((entries) {
-        return Future.wait(entries.mappedBy((entry) {
+        return Future.wait(entries.map((entry) {
           return fileExists(entry).then((isFile) {
             // Skip directories.
             if (!isFile) return null;
diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart
index 30bfeb16..d562997f 100644
--- a/lib/src/entrypoint.dart
+++ b/lib/src/entrypoint.dart
@@ -130,7 +130,7 @@ class Entrypoint {
   /// [packageVersions], and writes a [LockFile].
   Future _installDependencies(List<PackageId> packageVersions) {
     return cleanDir(path).then((_) {
-      return Future.wait(packageVersions.mappedBy((id) {
+      return Future.wait(packageVersions.map((id) {
         if (id.isRoot) return new Future.immediate(id);
         return install(id);
       }));
@@ -207,7 +207,7 @@ class Entrypoint {
       return _linkSecondaryPackageDir(dir)
         .then((_) => _listDirWithoutPackages(dir))
         .then((files) {
-        return Future.wait(files.mappedBy((file) {
+        return Future.wait(files.map((file) {
           return dirExists(file).then((isDir) {
             if (!isDir) return;
             return _linkSecondaryPackageDir(file);
@@ -222,7 +222,7 @@ class Entrypoint {
   /// files and `package` files.
   Future<List<String>> _listDirWithoutPackages(dir) {
     return listDir(dir).then((files) {
-      return Future.wait(files.mappedBy((file) {
+      return Future.wait(files.map((file) {
         if (basename(file) == 'packages') return new Future.immediate([]);
         return dirExists(file).then((isDir) {
           if (!isDir) return [];
diff --git a/lib/src/hosted_source.dart b/lib/src/hosted_source.dart
index 81a80574..b774bc01 100644
--- a/lib/src/hosted_source.dart
+++ b/lib/src/hosted_source.dart
@@ -39,7 +39,7 @@ class HostedSource extends Source {
     return httpClient.read(fullUrl).then((body) {
       var doc = json.parse(body);
       return doc['versions']
-          .mappedBy((version) => new Version.parse(version))
+          .map((version) => new Version.parse(version))
           .toList();
     }).catchError((ex) {
       _throwFriendlyError(ex, parsed.first, parsed.last);
diff --git a/lib/src/io.dart b/lib/src/io.dart
index 79f0a065..d45e9298 100644
--- a/lib/src/io.dart
+++ b/lib/src/io.dart
@@ -22,7 +22,7 @@ final NEWLINE_PATTERN = new RegExp("\r\n?|\n\r?");
 /// [File] objects.
 String join(part1, [part2, part3, part4, part5, part6, part7, part8]) {
   var parts = [part1, part2, part3, part4, part5, part6, part7, part8]
-      .mappedBy((part) => part == null ? null : _getPath(part)).toList();
+      .map((part) => part == null ? null : _getPath(part)).toList();
 
   return path.join(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5],
       parts[6], parts[7]);
@@ -873,7 +873,7 @@ InputStream createTarGz(List contents, {baseDir}) {
 
   if (baseDir == null) baseDir = path.current;
   baseDir = getFullPath(baseDir);
-  contents = contents.mappedBy((entry) {
+  contents = contents.map((entry) {
     entry = getFullPath(entry);
     if (!isBeneath(entry, baseDir)) {
       throw 'Entry $entry is not inside $baseDir.';
@@ -883,7 +883,7 @@ InputStream createTarGz(List contents, {baseDir}) {
 
   if (Platform.operatingSystem != "windows") {
     var args = ["--create", "--gzip", "--directory", baseDir];
-    args.addAll(contents.mappedBy(_getPath));
+    args.addAll(contents.map(_getPath));
     // TODO(nweiz): It's possible that enough command-line arguments will make
     // the process choke, so at some point we should save the arguments to a
     // file and pass them in via --files-from for tar and -i@filename for 7zip.
@@ -903,7 +903,7 @@ InputStream createTarGz(List contents, {baseDir}) {
     // Create the tar file.
     var tarFile = join(tempDir, "intermediate.tar");
     var args = ["a", "-w$baseDir", tarFile];
-    args.addAll(contents.mappedBy((entry) => '-i!"$entry"'));
+    args.addAll(contents.map((entry) => '-i!"$entry"'));
 
     // Note: This line of code gets munged by create_sdk.py to be the correct
     // relative path to 7zip in the SDK.
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 7710ac19..8d17f955 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -162,7 +162,7 @@ String mapToQuery(Map<String, String> map) {
     value = (value == null || value.isEmpty) ? null : encodeUriComponent(value);
     pairs.add([key, value]);
   });
-  return Strings.join(pairs.mappedBy((pair) {
+  return Strings.join(pairs.map((pair) {
     if (pair[1] == null) return pair[0];
     return "${pair[0]}=${pair[1]}";
   }), "&");
diff --git a/lib/src/validator.dart b/lib/src/validator.dart
index 5ec0f233..4b417e98 100644
--- a/lib/src/validator.dart
+++ b/lib/src/validator.dart
@@ -53,12 +53,12 @@ abstract class Validator {
       new DirectoryValidator(entrypoint)
     ];
 
-    return Future.wait(validators.mappedBy((validator) => validator.validate()))
+    return Future.wait(validators.map((validator) => validator.validate()))
       .then((_) {
       var errors =
-          flatten(validators.mappedBy((validator) => validator.errors));
+          flatten(validators.map((validator) => validator.errors));
       var warnings =
-          flatten(validators.mappedBy((validator) => validator.warnings));
+          flatten(validators.map((validator) => validator.warnings));
 
       if (!errors.isEmpty) {
         log.error("Missing requirements:");
diff --git a/lib/src/validator/directory.dart b/lib/src/validator/directory.dart
index 132bdd72..09a6c7e9 100644
--- a/lib/src/validator/directory.dart
+++ b/lib/src/validator/directory.dart
@@ -19,7 +19,7 @@ class DirectoryValidator extends Validator {
 
   Future validate() {
     return listDir(entrypoint.root.dir).then((dirs) {
-      return Future.wait(dirs.mappedBy((dir) {
+      return Future.wait(dirs.map((dir) {
         return dirExists(dir).then((exists) {
           if (!exists) return;
 
diff --git a/lib/src/validator/lib.dart b/lib/src/validator/lib.dart
index e6798476..faee7290 100644
--- a/lib/src/validator/lib.dart
+++ b/lib/src/validator/lib.dart
@@ -31,7 +31,7 @@ class LibValidator extends Validator {
       }
 
       return listDir(libDir).then((files) {
-        files = files.mappedBy((file) => relativeTo(file, libDir)).toList();
+        files = files.map((file) => relativeTo(file, libDir)).toList();
         if (files.isEmpty) {
           errors.add('You must have a non-empty "lib" directory.\n'
               "Without that, users cannot import any code from your package.");
diff --git a/lib/src/validator/license.dart b/lib/src/validator/license.dart
index 25556f85..8c32548c 100644
--- a/lib/src/validator/license.dart
+++ b/lib/src/validator/license.dart
@@ -20,7 +20,7 @@ class LicenseValidator extends Validator {
     return listDir(entrypoint.root.dir).then((files) {
       var licenseLike = new RegExp(
           r"^([a-zA-Z0-9]+[-_])?(LICENSE|COPYING)(\..*)?$");
-      if (files.mappedBy(basename).any(licenseLike.hasMatch)) return;
+      if (files.map(basename).any(licenseLike.hasMatch)) return;
 
       errors.add(
           "You must have a COPYING or LICENSE file in the root directory.\n"
diff --git a/lib/src/validator/name.dart b/lib/src/validator/name.dart
index eb1bc850..7c4778c8 100644
--- a/lib/src/validator/name.dart
+++ b/lib/src/validator/name.dart
@@ -52,7 +52,7 @@ class NameValidator extends Validator {
       return listDir(libDir, recursive: true);
     }).then((files) {
       return files
-          .mappedBy((file) => relativeTo(file, dirname(libDir)))
+          .map((file) => relativeTo(file, dirname(libDir)))
           .where((file) => !splitPath(file).contains("src") &&
                            path.extension(file) == '.dart')
           .toList();
diff --git a/lib/src/version.dart b/lib/src/version.dart
index 18e15a5f..06c14fd4 100644
--- a/lib/src/version.dart
+++ b/lib/src/version.dart
@@ -192,7 +192,7 @@ class Version implements Comparable, VersionConstraint {
   /// Splits a string of dot-delimited identifiers into their component parts.
   /// Identifiers that are numeric are converted to numbers.
   List _splitParts(String text) {
-    return text.split('.').mappedBy((part) {
+    return text.split('.').map((part) {
       try {
         return int.parse(part);
       } on FormatException catch (ex) {
diff --git a/lib/src/version_solver.dart b/lib/src/version_solver.dart
index 21f8cad5..a45af911 100644
--- a/lib/src/version_solver.dart
+++ b/lib/src/version_solver.dart
@@ -189,12 +189,12 @@ class VersionSolver {
       }
     }
 
-    return dependency.dependers.mappedBy(getDependency).any((subdependency) =>
+    return dependency.dependers.map(getDependency).any((subdependency) =>
         tryUnlockDepender(subdependency, seen));
   }
 
   List<PackageId> buildResults() {
-    return _packages.values.where((dep) => dep.isDependedOn).mappedBy((dep) {
+    return _packages.values.where((dep) => dep.isDependedOn).map((dep) {
       var description = dep.description;
 
       // If the lockfile contains a fully-resolved description for the package,
@@ -507,7 +507,7 @@ class Dependency {
   VersionConstraint get constraint {
     if (_refs.isEmpty) return null;
     return new VersionConstraint.intersection(
-        _refs.values.mappedBy((ref) => ref.constraint));
+        _refs.values.map((ref) => ref.constraint));
   }
 
   /// The source of this dependency's package.
diff --git a/test/command_line_config.dart b/test/command_line_config.dart
index 790e91ec..71df35e0 100644
--- a/test/command_line_config.dart
+++ b/test/command_line_config.dart
@@ -83,7 +83,7 @@ class CommandLineConfiguration extends Configuration {
     if (stack.length == 0) return;
 
     // Figure out the longest path so we know how much to pad.
-    int longest = stack.mappedBy((frame) => frame.location.length).max();
+    int longest = stack.map((frame) => frame.location.length).max();
 
     // Print out the stack trace nicely formatted.
     for (var frame in stack) {
@@ -108,7 +108,7 @@ class CommandLineConfiguration extends Configuration {
   String _indent(String str) {
     // TODO(nweiz): Use this simpler code once issue 2980 is fixed.
     // return str.replaceAll(new RegExp("^", multiLine: true), "  ");
-    return Strings.join(str.split("\n").mappedBy((line) => "  $line"), "\n");
+    return Strings.join(str.split("\n").map((line) => "  $line"), "\n");
   }
 }
 
diff --git a/test/test_pub.dart b/test/test_pub.dart
index 66d9434f..eeaddc96 100644
--- a/test/test_pub.dart
+++ b/test/test_pub.dart
@@ -190,7 +190,7 @@ void servePackages(List<Map> pubspecs) {
           file('$name.json',
               json.stringify({'versions': versions})),
           dir(name, [
-            dir('versions', flatten(versions.mappedBy((version) {
+            dir('versions', flatten(versions.map((version) {
               return [
                 file('$version.yaml', _servedPackages[name][version]),
                 tar('$version.tar.gz', [
@@ -529,7 +529,7 @@ void schedulePub({List args, Pattern output, Pattern error,
         if (error == null) {
           // If we aren't validating the error, still show it on failure.
           failures.add('Pub stderr:');
-          failures.addAll(result.stderr.mappedBy((line) => '| $line'));
+          failures.addAll(result.stderr.map((line) => '| $line'));
         }
 
         throw new ExpectException(Strings.join(failures, '\n'));
@@ -701,7 +701,7 @@ void _validateOutputRegex(List<String> failures, String pipe,
     failures.add('Expected $pipe to match "${expected.pattern}" but got none.');
   } else {
     failures.add('Expected $pipe to match "${expected.pattern}" but got:');
-    failures.addAll(actual.mappedBy((line) => '| $line'));
+    failures.addAll(actual.map((line) => '| $line'));
   }
 }
 
@@ -746,7 +746,7 @@ void _validateOutputString(List<String> failures, String pipe,
   // If any lines mismatched, show the expected and actual.
   if (failed) {
     failures.add('Expected $pipe:');
-    failures.addAll(expected.mappedBy((line) => '| $line'));
+    failures.addAll(expected.map((line) => '| $line'));
     failures.add('Got:');
     failures.addAll(results);
   }
@@ -930,7 +930,7 @@ class DirectoryDescriptor extends Descriptor {
 
       // Recursively create all of its children.
       final childFutures =
-          contents.mappedBy((child) => child.create(dir)).toList();
+          contents.map((child) => child.create(dir)).toList();
       // Only complete once all of the children have been created too.
       return Future.wait(childFutures).then((_) => dir);
     });
@@ -950,7 +950,7 @@ class DirectoryDescriptor extends Descriptor {
     return _validateOneMatch(path, (dir) {
       // Validate each of the items in this directory.
       final entryFutures =
-          contents.mappedBy((entry) => entry.validate(dir)).toList();
+          contents.map((entry) => entry.validate(dir)).toList();
 
       // If they are all valid, the directory is valid.
       return Future.wait(entryFutures).then((entries) => null);
@@ -1082,7 +1082,7 @@ class TarFileDescriptor extends Descriptor {
     var tempDir;
     return createTempDir().then((_tempDir) {
       tempDir = _tempDir;
-      return Future.wait(contents.mappedBy((child) => child.create(tempDir)));
+      return Future.wait(contents.map((child) => child.create(tempDir)));
     }).then((createdContents) {
       return consumeInputStream(createTarGz(createdContents, baseDir: tempDir));
     }).then((bytes) {
@@ -1493,7 +1493,7 @@ Future _awaitObject(object) {
   // Unroll nested futures.
   if (object is Future) return object.then(_awaitObject);
   if (object is Collection) {
-    return Future.wait(object.mappedBy(_awaitObject).toList());
+    return Future.wait(object.map(_awaitObject).toList());
   }
   if (object is! Map) return new Future.immediate(object);
 
-- 
GitLab