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

Side by Side Diff: utils/pub/io.dart

Issue 13548002: Add Iterable.fold (and Stream.fold) which replace `reduce`. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/dom/templates/immutable_list_mixin.darttemplate ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// Helper functionality to make working with IO easier. 5 /// Helper functionality to make working with IO easier.
6 library io; 6 library io;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:isolate'; 10 import 'dart:isolate';
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 Future<bool> confirm(String message) { 321 Future<bool> confirm(String message) {
322 log.fine('Showing confirm message: $message'); 322 log.fine('Showing confirm message: $message');
323 stdoutSink.add("$message (y/n)? ".codeUnits); 323 stdoutSink.add("$message (y/n)? ".codeUnits);
324 return streamFirst(stdinLines) 324 return streamFirst(stdinLines)
325 .then((line) => new RegExp(r"^[yY]").hasMatch(line)); 325 .then((line) => new RegExp(r"^[yY]").hasMatch(line));
326 } 326 }
327 327
328 /// Reads and discards all output from [stream]. Returns a [Future] that 328 /// Reads and discards all output from [stream]. Returns a [Future] that
329 /// completes when the stream is closed. 329 /// completes when the stream is closed.
330 Future drainStream(Stream stream) { 330 Future drainStream(Stream stream) {
331 return stream.reduce(null, (x, y) {}); 331 return stream.fold(null, (x, y) {});
332 } 332 }
333 333
334 /// Returns a [EventSink] that pipes all data to [consumer] and a [Future] that 334 /// Returns a [EventSink] that pipes all data to [consumer] and a [Future] that
335 /// will succeed when [EventSink] is closed or fail with any errors that occur 335 /// will succeed when [EventSink] is closed or fail with any errors that occur
336 /// while writing. 336 /// while writing.
337 Pair<EventSink, Future> consumerToSink(StreamConsumer consumer) { 337 Pair<EventSink, Future> consumerToSink(StreamConsumer consumer) {
338 var controller = new StreamController(); 338 var controller = new StreamController();
339 var done = controller.stream.pipe(consumer); 339 var done = controller.stream.pipe(consumer);
340 return new Pair<EventSink, Future>(controller.sink, done); 340 return new Pair<EventSink, Future>(controller.sink, done);
341 } 341 }
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 const PubProcessResult(this.stdout, this.stderr, this.exitCode); 734 const PubProcessResult(this.stdout, this.stderr, this.exitCode);
735 735
736 bool get success => exitCode == 0; 736 bool get success => exitCode == 0;
737 } 737 }
738 738
739 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. 739 /// Gets a [Uri] for [uri], which can either already be one, or be a [String].
740 Uri _getUri(uri) { 740 Uri _getUri(uri) {
741 if (uri is Uri) return uri; 741 if (uri is Uri) return uri;
742 return Uri.parse(uri); 742 return Uri.parse(uri);
743 } 743 }
OLDNEW
« no previous file with comments | « tools/dom/templates/immutable_list_mixin.darttemplate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698