Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 main() { | |
| 6 List<int> list1 = <int>[1, 2, 3]; | |
| 7 List<int> list2 = const <int>[4, 5]; | |
| 8 List<String> list3 = <String>[]; | |
| 9 Set<int> set1 = new Set<int>(); | |
| 10 set1..add(11) | |
|
Lasse Reichstein Nielsen
2013/01/24 06:49:32
Why not set1.addAll([1, 2, 3]); ?
What is the purp
floitsch
2013/01/24 13:48:34
Done.
| |
| 11 ..add(12) | |
| 12 ..add(13); | |
| 13 Set set2 = new Set(); | |
| 14 | |
| 15 Iterable mapped = list1.mappedBy((x) => x + 1); | |
|
Lasse Reichstein Nielsen
2013/01/24 06:49:32
Why "Iterable" and not "List"?
floitsch
2013/01/24 13:48:34
Because I want to prepare for the change back.
| |
| 16 Expect.isTrue(mapped is List); | |
| 17 Expect.listEquals([2, 3, 4], mapped.toList()); | |
|
Lasse Reichstein Nielsen
2013/01/24 06:49:32
And why .toList then?
floitsch
2013/01/24 13:48:34
removed.
| |
| 18 | |
| 19 mapped = mapped.mappedBy((x) => x + 1); | |
| 20 Expect.isTrue(mapped is List); | |
| 21 Expect.listEquals([3, 4, 5], mapped.toList()); | |
| 22 | |
| 23 mapped = list2.mappedBy((x) => x + 1); | |
| 24 Expect.isTrue(mapped is List); | |
| 25 Expect.listEquals([5, 6], mapped.toList()); | |
| 26 | |
| 27 mapped = mapped.mappedBy((x) => x + 1); | |
| 28 Expect.isTrue(mapped is List); | |
| 29 Expect.listEquals([6, 7], mapped.toList()); | |
| 30 | |
| 31 mapped = list3.mappedBy((x) => x + 1); | |
| 32 Expect.isTrue(mapped is List); | |
| 33 Expect.listEquals([], mapped.toList()); | |
| 34 | |
| 35 mapped = mapped.mappedBy((x) => x + 1); | |
| 36 Expect.isTrue(mapped is List); | |
| 37 Expect.listEquals([], mapped.toList()); | |
| 38 | |
| 39 var expected = new Set<int>()..add(12)..add(13)..add(14); | |
| 40 mapped = set1.mappedBy((x) => x + 1); | |
| 41 Expect.isFalse(mapped is List); | |
| 42 Expect.setEquals(expected, mapped.toSet()); | |
| 43 | |
| 44 expected = new Set<int>()..add(13)..add(14)..add(15); | |
| 45 mapped = mapped.mappedBy((x) => x + 1); | |
| 46 Expect.isFalse(mapped is List); | |
| 47 Expect.setEquals(expected, mapped.toSet()); | |
| 48 | |
| 49 mapped = set2.mappedBy((x) => x + 1); | |
| 50 Expect.isFalse(mapped is List); | |
| 51 Expect.listEquals([], mapped.toList()); | |
| 52 | |
| 53 mapped = mapped.mappedBy((x) => x + 1); | |
| 54 Expect.isFalse(mapped is List); | |
| 55 Expect.listEquals([], mapped.toList()); | |
| 56 | |
| 57 } | |
| OLD | NEW |