Skip to content

Commit 65a32c7

Browse files
committed
updated to nnbd
1 parent 488a765 commit 65a32c7

20 files changed

+117
-139
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2020, MarchDev Toolkit
3+
Copyright (c) 2021, MarchDev Toolkit
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

example/bin/main.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
1+
// Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'src/iterable.set.examples.dart';
6-
import 'src/iterable.math.examples.dart';
75
import 'src/iterable.common.examples.dart';
86
import 'src/iterable.comparable.examples.dart';
7+
import 'src/iterable.math.examples.dart';
8+
import 'src/iterable.set.examples.dart';
99

1010
main(List<String> arguments) {
1111
iterableCommonTest();

example/bin/src/iterable.common.examples.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
1+
// Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

@@ -218,7 +218,7 @@ void _notNull() {
218218

219219
final numCollection = [null, ..._numCollection, null];
220220

221-
final result = numCollection.notNull;
221+
final result = numCollection.notNull as Iterable<int>;
222222
assert(result.toString() == _numCollection.toString());
223223
print(result.toString());
224224

@@ -240,7 +240,7 @@ void _group() {
240240
Pet("dog", "Rex"),
241241
],
242242
}.toString()); // true
243-
print(result?.toString());
243+
print(result.toString());
244244

245245
print('---- ----- ----\n');
246246
}
@@ -255,7 +255,7 @@ void _groupMap() {
255255
true: 2,
256256
false: 1,
257257
}.toString()); // true
258-
print(result?.toString());
258+
print(result.toString());
259259

260260
print('---- -------- ----\n');
261261
}

example/bin/src/iterable.comparable.examples.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
1+
// Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

@@ -19,12 +19,12 @@ void _min() {
1919
// [ Pet("rat", "Mike"), Pet("dog", "Rex"), Pet("cat", "Lucy") ]
2020
var result = _collection.min;
2121
assert(result == Pet("cat", "Lucy")); // true
22-
print(result?.toString());
22+
print(result.toString());
2323

2424
try {
2525
result = _emptyCollection.min; // []
2626
assert(false);
27-
print(result?.toString());
27+
print(result.toString());
2828
} catch (e) {
2929
assert(e is StateError); // true (No element)
3030
print(e.toString());
@@ -39,12 +39,12 @@ void _minWhere() {
3939
// [ Pet("rat", "Mike"), Pet("dog", "Rex"), Pet("cat", "Lucy") ]
4040
var result = _collection.minWhere((_) => _.name != "cat");
4141
assert(result == Pet("dog", "Rex")); // true
42-
print(result?.toString());
42+
print(result.toString());
4343

4444
try {
4545
result = _collection.minWhere((_) => _.name == "rabbit"); // []
4646
assert(false);
47-
print(result?.toString());
47+
print(result.toString());
4848
} catch (e) {
4949
assert(e is StateError); // true (No element)
5050
print(e.toString());
@@ -89,12 +89,12 @@ void _max() {
8989
// [ Pet("rat", "Mike"), Pet("dog", "Rex"), Pet("cat", "Lucy") ]
9090
var result = _collection.max;
9191
assert(result == Pet("rat", "Mike")); // true
92-
print(result?.toString());
92+
print(result.toString());
9393

9494
try {
9595
result = _emptyCollection.max; // []
9696
assert(false);
97-
print(result?.toString());
97+
print(result.toString());
9898
} catch (e) {
9999
assert(e is StateError); // true (No element)
100100
print(e.toString());
@@ -109,12 +109,12 @@ void _maxWhere() {
109109
// [ Pet("rat", "Mike"), Pet("dog", "Rex"), Pet("cat", "Lucy") ]
110110
var result = _collection.maxWhere((_) => _.name != "cat");
111111
assert(result == Pet("rat", "Mike")); // true
112-
print(result?.toString());
112+
print(result.toString());
113113

114114
try {
115115
result = _collection.maxWhere((_) => _.name == "rabbit"); // []
116116
assert(false);
117-
print(result?.toString());
117+
print(result.toString());
118118
} catch (e) {
119119
assert(e is StateError); // true (No element)
120120
print(e.toString());

example/bin/src/iterable.math.examples.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
1+
// Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

example/bin/src/iterable.set.examples.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
1+
// Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

@@ -21,6 +21,6 @@ void iterableSetTest() {
2121
print(collectionOne.intersectionWhere(collectionTwo, (_) => _ < 4)); // []
2222
print(collectionOne.differenceWhere(collectionTwo, (_) => _ < 4)); // [2]
2323
print(collectionTwo.differenceWhere(collectionOne, (_) => _ < 4)); // [1, 3]
24-
24+
2525
print('---- ------------ ----\n');
2626
}

example/bin/src/pet.model.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
1+
// Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: flinq_example
22
description: Example command line application of flinq package.
33

44
environment:
5-
sdk: '>=2.6.0 <3.0.0'
5+
sdk: '>=2.12.0 <3.0.0'
66

77
dependencies:
88
flinq:

lib/flinq.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
1+
// Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

55
library flinq;
66

7-
export 'src/iterable.comparable.extension.dart';
87
export 'src/iterable.common.extension.dart';
8+
export 'src/iterable.comparable.extension.dart';
99
export 'src/iterable.math.extension.dart';
1010
export 'src/iterable.set.extension.dart';

lib/src/iterable.common.extension.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
1+
// Copyright (c) 2021, the MarchDev Toolkit project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:collection/collection.dart' show IterableExtension;
6+
57
/// Common extensions for `Iterable`
68
extension IterableCommonExtension<T> on Iterable<T> {
79
/// Returns the first element.
810
///
911
/// If `this` is empty, the result of invoking is [null].
1012
/// Otherwise returns the first element in the iteration order,
1113
/// equivalent to `this.elementAt(0)`.
12-
T get firstOrNull => this.firstWhere((_) => true, orElse: () => null);
14+
T? get firstOrNull => this.firstWhereOrNull((_) => true);
1315

1416
/// Returns the last element.
1517
///
@@ -19,21 +21,20 @@ extension IterableCommonExtension<T> on Iterable<T> {
1921
/// Some iterables may have more efficient ways to find the last element
2022
/// (for example a list can directly access the last element,
2123
/// without iterating through the previous ones).
22-
T get lastOrNull => this.lastWhere((_) => true, orElse: () => null);
24+
T? get lastOrNull => this.lastWhereOrNull((_) => true);
2325

2426
/// Checks that this iterable has only one element, and returns that element.
2527
///
2628
/// If `this` has no element, the result is [null].
2729
/// Throws a [StateError] if `this` has more than one element.
28-
T get singleOrNull => this.singleWhere((_) => true, orElse: () => null);
30+
T? get singleOrNull => this.singleWhereOrNull((_) => true);
2931

3032
/// Returns the first element that satisfies the given predicate [test].
3133
///
3234
/// Iterates through elements and returns the first to satisfy [test].
3335
///
3436
/// If no element satisfies [test], the result of invoking is [null].
35-
T firstOrNullWhere(bool test(T element)) =>
36-
this.firstWhere(test, orElse: () => null);
37+
T? firstOrNullWhere(bool test(T element)) => this.firstWhereOrNull(test);
3738

3839
/// Returns the last element that satisfies the given predicate [test].
3940
///
@@ -45,17 +46,15 @@ extension IterableCommonExtension<T> on Iterable<T> {
4546
/// and finally returns that last one that matched.
4647
///
4748
/// If no element satisfies [test], the result of invoking is [null].
48-
T lastOrNullWhere(bool test(T element)) =>
49-
this.lastWhere(test, orElse: () => null);
49+
T? lastOrNullWhere(bool test(T element)) => this.lastWhereOrNull(test);
5050

5151
/// Returns the single element that satisfies [test].
5252
///
5353
/// Checks elements to see if `test(element)` returns true.
5454
/// If exactly one element satisfies [test], that element is returned.
5555
/// If more than one matching element is found, throws [StateError].
5656
/// If no matching element is found, returns [null].
57-
T singleOrNullWhere(bool test(T element)) =>
58-
this.singleWhere(test, orElse: () => null);
57+
T? singleOrNullWhere(bool test(T element)) => this.singleWhereOrNull(test);
5958

6059
/// Maps [Iterable] and casts it to a [List].
6160
///
@@ -120,7 +119,7 @@ extension IterableCommonExtension<T> on Iterable<T> {
120119
final key = by(value);
121120

122121
if (map.containsKey(key)) {
123-
map[key].add(value);
122+
map[key]!.add(value);
124123
} else {
125124
map[key] = <T>[value];
126125
}

0 commit comments

Comments
 (0)