| 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:crypto'; | 10 import 'dart:crypto'; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 helper(nested); | 68 helper(nested); |
| 69 return result; | 69 return result; |
| 70 } | 70 } |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * Asserts that [iter] contains only one element, and returns it. | 73 * Asserts that [iter] contains only one element, and returns it. |
| 74 */ | 74 */ |
| 75 only(Iterable iter) { | 75 only(Iterable iter) { |
| 76 var iterator = iter.iterator(); | 76 var iterator = iter.iterator(); |
| 77 assert(iterator.hasNext()); | 77 assert(iterator.hasNext); |
| 78 var obj = iterator.next(); | 78 var obj = iterator.next(); |
| 79 assert(!iterator.hasNext()); | 79 assert(!iterator.hasNext); |
| 80 return obj; | 80 return obj; |
| 81 } | 81 } |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Returns a set containing all elements in [minuend] that are not in | 84 * Returns a set containing all elements in [minuend] that are not in |
| 85 * [subtrahend]. | 85 * [subtrahend]. |
| 86 */ | 86 */ |
| 87 Set setMinus(Collection minuend, Collection subtrahend) { | 87 Set setMinus(Collection minuend, Collection subtrahend) { |
| 88 var minuendSet = new Set.from(minuend); | 88 var minuendSet = new Set.from(minuend); |
| 89 minuendSet.removeAll(subtrahend); | 89 minuendSet.removeAll(subtrahend); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes()).digest()); | 122 CryptoUtils.bytesToHex(new SHA1().update(source.charCodes()).digest()); |
| 123 | 123 |
| 124 /** | 124 /** |
| 125 * Returns a [Future] that completes in [milliSeconds]. | 125 * Returns a [Future] that completes in [milliSeconds]. |
| 126 */ | 126 */ |
| 127 Future sleep(int milliSeconds) { | 127 Future sleep(int milliSeconds) { |
| 128 var completer = new Completer(); | 128 var completer = new Completer(); |
| 129 new Timer(milliSeconds, completer.complete); | 129 new Timer(milliSeconds, completer.complete); |
| 130 return completer.future; | 130 return completer.future; |
| 131 } | 131 } |
| OLD | NEW |