Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into iterablex
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Jun 9, 2024
2 parents 095c73d + e9219c7 commit ecb688f
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ updates:
interval: monthly
labels:
- autosubmit
groups:
github-actions:
patterns:
- "*"
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
- uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30
with:
sdk: ${{ matrix.sdk }}
- id: install
Expand All @@ -48,8 +48,8 @@ jobs:
os: [ubuntu-latest]
sdk: [3.1.0, dev]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
- uses: dart-lang/setup-dart@f0ead981b4d9a35b37f30d36160575d60931ec30
with:
sdk: ${{ matrix.sdk }}
- id: install
Expand All @@ -61,3 +61,6 @@ jobs:
- name: Run Chrome tests
run: dart test --platform chrome --test-randomize-ordering-seed=random
if: always() && steps.install.outcome == 'success'
- name: Run Chrome tests - wasm
run: dart test --platform chrome --compiler dart2wasm
if: always() && steps.install.outcome == 'success' && matrix.sdk == 'dev'
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
- Shuffle `IterableExtension.sample` results.
- Fix `mergeSort` when the runtime iterable generic is a subtype of the static
generic.
- `CanonicalizedMap`: added constructor `fromEntries`.
- Mark "mixin" classes as `mixin`.
- Deprecate `transitiveClosure`. Consider using `package:graphs`.
- Remove `firstOrNull`, `lastOrNull`, `singleOrNull` and `elementAtOrNull()`
from `IterableExtensions`. Since Dart 3.0, exact equivalents to these are
available in Dart core, so 'package:collection' would only be shadowing these.
- Deprecate `whereNotNull()` from `IterableNullableExtension`. Use `nonNulls`
instead - this is an equivalent extension available in Dart core since
version 3.0.
- Require Dart `^3.1.0`
- Mark "mixin" classes as `mixin`.

## 1.18.0

Expand Down
2 changes: 1 addition & 1 deletion lib/algorithms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/// Import `collection.dart` instead.
@Deprecated('Will be removed in collection 2.0.0.')
library dart.pkg.collection.algorithms;
library;

export 'src/algorithms.dart'
show binarySearch, insertionSort, lowerBound, mergeSort, reverse, shuffle;
2 changes: 1 addition & 1 deletion lib/equality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

/// Import `collection.dart` instead.
@Deprecated('Will be removed in collection 2.0.0.')
library dart.pkg.collection.equality;
library;

export 'src/equality.dart';
2 changes: 1 addition & 1 deletion lib/iterable_zip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

/// Import `collection.dart` instead.
@Deprecated('Will be removed in collection 2.0.0.')
library dart.pkg.collection.iterable_zip;
library;

export 'src/iterable_zip.dart';
2 changes: 1 addition & 1 deletion lib/priority_queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

/// Import `collection.dart` instead.
@Deprecated('Will be removed in collection 2.0.0.')
library dart.pkg.collection.priority_queue;
library;

export 'src/priority_queue.dart';
2 changes: 1 addition & 1 deletion lib/src/algorithms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

/// A selection of data manipulation algorithms.
library pkg.collection.algorithms;
library;

import 'dart:math' show Random;

Expand Down
17 changes: 17 additions & 0 deletions lib/src/canonicalized_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ class CanonicalizedMap<C, K, V> implements Map<K, V> {
addAll(other);
}

/// Creates a canonicalized map that is initialized with the key/value pairs
/// of [entries].
///
/// The [canonicalize] function should return the canonical value for the
/// given key. Keys with the same canonical value are considered equivalent.
///
/// The [isValidKey] function is called before calling [canonicalize] for
/// methods that take arbitrary objects. It can be used to filter out keys
/// that can't be canonicalized.
CanonicalizedMap.fromEntries(
Iterable<MapEntry<K, V>> entries, C Function(K key) canonicalize,
{bool Function(K key)? isValidKey})
: _canonicalize = canonicalize,
_isValidKeyFn = isValidKey {
addEntries(entries);
}

CanonicalizedMap._(
this._canonicalize, this._isValidKeyFn, Map<C, MapEntry<K, V>> base) {
_base.addAll(base);
Expand Down
1 change: 1 addition & 0 deletions lib/src/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ S? maxBy<S, T>(Iterable<S> values, T Function(S) orderBy,
/// that vertex has no outgoing edges. This isn't checked, but if it's not
/// satisfied, the function may crash or provide unexpected output. For example,
/// `{"a": ["b"]}` is not valid, but `{"a": ["b"], "b": []}` is.
@Deprecated('This method will be removed. Consider using package:graphs.')
Map<T, Set<T>> transitiveClosure<T>(Map<T, Iterable<T>> graph) {
// This uses [Warshall's algorithm][], modified not to add a vertex from each
// node to itself.
Expand Down
1 change: 1 addition & 0 deletions lib/src/iterable_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ extension IterableNullableExtension<T extends Object> on Iterable<T?> {
/// of this iterable, in their original iteration order.
///
/// For an `Iterable<X?>`, this method is equivalent to `.whereType<X>()`.
@Deprecated('Use .nonNulls instead.')
Iterable<T> whereNotNull() sync* {
for (var element in this) {
if (element != null) yield element;
Expand Down
2 changes: 1 addition & 1 deletion lib/wrappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/// Import `collection.dart` instead.
@Deprecated('Will be removed in collection 2.0.0.')
library dart.pkg.collection.wrappers;
library;

export 'src/canonicalized_map.dart';
export 'src/unmodifiable_wrappers.dart';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ environment:
sdk: ^3.1.0

dev_dependencies:
dart_flutter_team_lints: ^2.0.0
dart_flutter_team_lints: ^3.0.0
test: ^1.16.0
18 changes: 18 additions & 0 deletions test/canonicalized_map_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ void main() {
});
});

group('CanonicalizedMap.fromEntries', () {
test('canonicalizes its keys', () {
var map = CanonicalizedMap.fromEntries(
{'1': 'value 1', '2': 'value 2', '3': 'value 3'}.entries, int.parse);
expect(map['01'], equals('value 1'));
expect(map['02'], equals('value 2'));
expect(map['03'], equals('value 3'));
});

test('uses the final value for collisions', () {
var map = CanonicalizedMap.fromEntries(
{'1': 'value 1', '01': 'value 2', '001': 'value 3'}.entries,
int.parse);
expect(map.length, equals(1));
expect(map['0001'], equals('value 3'));
});
});

group('CanonicalizedMap.toMapOfCanonicalKeys', () {
test('convert to a `Map<C,V>`', () {
var map = CanonicalizedMap.from(
Expand Down
42 changes: 36 additions & 6 deletions test/extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -836,17 +836,47 @@ void main() {
group('of nullable', () {
group('.whereNotNull', () {
test('empty', () {
expect(iterable(<int?>[]).whereNotNull(), isEmpty);
expect(
iterable(<int?>[])
.whereNotNull(), // ignore: deprecated_member_use_from_same_package
isEmpty);
});
test('single', () {
expect(iterable(<int?>[null]).whereNotNull(), isEmpty);
expect(iterable(<int?>[1]).whereNotNull(), [1]);
expect(
iterable(<int?>[
null
]).whereNotNull(), // ignore: deprecated_member_use_from_same_package
isEmpty);
expect(
iterable(<int?>[
1
]).whereNotNull(), // ignore: deprecated_member_use_from_same_package
[1]);
});
test('multiple', () {
expect(iterable(<int?>[1, 3, 5]).whereNotNull(), [1, 3, 5]);
expect(iterable(<int?>[null, null, null]).whereNotNull(), isEmpty);
expect(
iterable(<int?>[1, null, 3, null, 5]).whereNotNull(), [1, 3, 5]);
iterable(<int?>[
1,
3,
5
]).whereNotNull(), // ignore: deprecated_member_use_from_same_package
[1, 3, 5]);
expect(
iterable(<int?>[
null,
null,
null
]).whereNotNull(), // ignore: deprecated_member_use_from_same_package
isEmpty);
expect(
iterable(<int?>[
1,
null,
3,
null,
5
]).whereNotNull(), // ignore: deprecated_member_use_from_same_package
[1, 3, 5]);
});
});
});
Expand Down
7 changes: 2 additions & 5 deletions test/functions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: deprecated_member_use_from_same_package

import 'package:collection/collection.dart';
import 'package:test/test.dart';

void main() {
group('mapMap()', () {
test('with an empty map returns an empty map', () {
expect(
// ignore: deprecated_member_use_from_same_package
mapMap({},
key: expectAsync2((_, __) {}, count: 0),
value: expectAsync2((_, __) {}, count: 0)),
Expand All @@ -18,7 +19,6 @@ void main() {

test('with no callbacks, returns a copy of the map', () {
var map = {'foo': 1, 'bar': 2};
// ignore: deprecated_member_use_from_same_package
var result = mapMap<String, int, String, int>(map);
expect(result, equals({'foo': 1, 'bar': 2}));

Expand All @@ -29,23 +29,20 @@ void main() {

test("maps the map's keys", () {
expect(
// ignore: deprecated_member_use_from_same_package
mapMap<String, int, dynamic, int>({'foo': 1, 'bar': 2},
key: (dynamic key, dynamic value) => key[value]),
equals({'o': 1, 'r': 2}));
});

test("maps the map's values", () {
expect(
// ignore: deprecated_member_use_from_same_package
mapMap<String, int, String, dynamic>({'foo': 1, 'bar': 2},
value: (dynamic key, dynamic value) => key[value]),
equals({'foo': 'o', 'bar': 'r'}));
});

test("maps both the map's keys and values", () {
expect(
// ignore: deprecated_member_use_from_same_package
mapMap({'foo': 1, 'bar': 2},
key: (dynamic key, dynamic value) => '$key$value',
value: (dynamic key, dynamic value) => key[value]),
Expand Down

0 comments on commit ecb688f

Please sign in to comment.