| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * Generic utility functions. Stuff that should possibly be in core. | 6 * Generic utility functions. Stuff that should possibly be in core. |
| 7 */ | 7 */ |
| 8 library utils; | 8 library utils; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 helper(nested); | 69 helper(nested); |
| 70 return result; | 70 return result; |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Asserts that [iter] contains only one element, and returns it. | 74 * Asserts that [iter] contains only one element, and returns it. |
| 75 */ | 75 */ |
| 76 only(Iterable iter) { | 76 only(Iterable iter) { |
| 77 var iterator = iter.iterator(); | 77 var iterator = iter.iterator; |
| 78 assert(iterator.hasNext); | 78 var currentIsValid = iterator.moveNext(); |
| 79 var obj = iterator.next(); | 79 assert(currentIsValid); |
| 80 assert(!iterator.hasNext); | 80 var obj = iterator.current; |
| 81 assert(!iterator.moveNext()); |
| 81 return obj; | 82 return obj; |
| 82 } | 83 } |
| 83 | 84 |
| 84 /** | 85 /** |
| 85 * Returns a set containing all elements in [minuend] that are not in | 86 * Returns a set containing all elements in [minuend] that are not in |
| 86 * [subtrahend]. | 87 * [subtrahend]. |
| 87 */ | 88 */ |
| 88 Set setMinus(Collection minuend, Collection subtrahend) { | 89 Set setMinus(Collection minuend, Collection subtrahend) { |
| 89 var minuendSet = new Set.from(minuend); | 90 var minuendSet = new Set.from(minuend); |
| 90 minuendSet.removeAll(subtrahend); | 91 minuendSet.removeAll(subtrahend); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes).digest()); | 124 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes).digest()); |
| 124 | 125 |
| 125 /** | 126 /** |
| 126 * Returns a [Future] that completes in [milliSeconds]. | 127 * Returns a [Future] that completes in [milliSeconds]. |
| 127 */ | 128 */ |
| 128 Future sleep(int milliSeconds) { | 129 Future sleep(int milliSeconds) { |
| 129 var completer = new Completer(); | 130 var completer = new Completer(); |
| 130 new Timer(milliSeconds, completer.complete); | 131 new Timer(milliSeconds, completer.complete); |
| 131 return completer.future; | 132 return completer.future; |
| 132 } | 133 } |
| OLD | NEW |