Skip to content

Commit 7d44763

Browse files
authored
Add extension methods to package:collection. (flutter#135)
Add a number of useful extension methods to `List` and `Iterable`, and to a few other types. A good part of these extensions are backed by the algorithms of `algorithms.dart`, which is expanded to support them: * Added `quickSort`. * Add extra optional `Random` argument to `shuffle`. * Generalize some of the functions in algorithms.dart to work on specific properties of the objects (`binarySearchBy`, `lowerBoundBy`, `insertionSortBy`, `quickSortBy`, `mergeSortBy`). The new methods are not exported from the library yet, they are intended to be used through the extension.
1 parent 898c839 commit 7d44763

14 files changed

+3353
-185
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- stage: test
2121
name: "Vm Tests"
2222
os: linux
23-
script: pub run --enable-experiment=non-nullable test -p vm
23+
script: pub run --enable-experiment=non-nullable test -p vm
2424
- stage: test
2525
name: "Web Tests"
2626
os: linux

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
* Remove the unusable setter `UnionSetController.set=`. This was mistakenly
44
added to the public API but could never be called.
55

6+
* Add extra optional `Random` argument to `shuffle`.
7+
8+
* Add a large number of extension methods on `Iterable` and `List` types,
9+
and on a few other types.
10+
These either provide easy access to the operations from `algorithms.dart`,
11+
or provide convenience variants of existing `Iterable` and `List` methods
12+
like `singleWhereOrNull` or `forEachIndexed`.
13+
614
## 1.15.0-nullsafety.3
715

816
* Allow 2.10 stable and 2.11.0 dev SDK versions.

analysis_options.yaml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: package:pedantic/analysis_options.yaml
1+
include: package:pedantic/analysis_options.1.9.0.yaml
22
analyzer:
33
errors:
44
unused_element: error
@@ -7,39 +7,21 @@ analyzer:
77
dead_code: error
88
enable-experiment:
99
- non-nullable
10-
1110
linter:
1211
rules:
1312
# Errors
14-
- avoid_empty_else
1513
- control_flow_in_finally
1614
- empty_statements
1715
- hash_and_equals
1816
- implementation_imports
1917
- test_types_in_equals
2018
- throw_in_finally
21-
- unrelated_type_equality_checks
22-
- valid_regexps
2319

2420
# Style
25-
- avoid_init_to_null
2621
- avoid_private_typedef_functions
2722
- avoid_renaming_method_parameters
28-
- avoid_return_types_on_setters
2923
- await_only_futures
3024
- camel_case_types
3125
- directives_ordering
32-
- empty_catches
33-
- empty_constructor_bodies
34-
- library_names
35-
- library_prefixes
3626
- non_constant_identifier_names
3727
- only_throw_errors
38-
- prefer_equal_for_default_values
39-
- prefer_final_fields
40-
- prefer_generic_function_type_aliases
41-
- prefer_is_not_empty
42-
- slash_for_doc_comments
43-
- type_init_formals
44-
- unnecessary_const
45-
- unnecessary_new

lib/algorithms.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
@Deprecated('Will be removed in collection 2.0.0.')
77
library dart.pkg.collection.algorithms;
88

9-
export 'src/algorithms.dart';
9+
export 'src/algorithms.dart'
10+
show binarySearch, insertionSort, lowerBound, mergeSort, shuffle, reverse;

lib/collection.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
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-
export 'src/algorithms.dart';
5+
export 'src/algorithms.dart'
6+
show binarySearch, insertionSort, lowerBound, mergeSort, shuffle, reverse;
67
export 'src/canonicalized_map.dart';
78
export 'src/combined_wrappers/combined_iterable.dart';
89
export 'src/combined_wrappers/combined_list.dart';
@@ -12,7 +13,9 @@ export 'src/equality.dart';
1213
export 'src/equality_map.dart';
1314
export 'src/equality_set.dart';
1415
export 'src/functions.dart';
16+
export 'src/iterable_extensions.dart';
1517
export 'src/iterable_zip.dart';
18+
export 'src/list_extensions.dart';
1619
export 'src/priority_queue.dart';
1720
export 'src/queue_list.dart';
1821
export 'src/union_set.dart';

0 commit comments

Comments
 (0)