-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce IterableMapEntryExtension
for use with Map.entries
.
#715
Conversation
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
PR Health
Breaking changes
|
Package | Change | Current Version | New Version | Needed Version | Looking good? |
---|---|---|---|---|---|
collection | Non-Breaking | 1.19.1 | 1.19.1-wip | 1.20.0 Got "1.19.1-wip" expected >= "1.20.0" (non-breaking changes) |
This check can be disabled by tagging the PR with skip-breaking-check
.
Changelog Entry ✔️
Package | Changed Files |
---|
Changes to files need to be accounted for in their respective changelogs.
Coverage ✔️
File | Coverage |
---|---|
pkgs/collection/lib/src/iterable_extensions.dart | 💚 100 % |
This check for test coverage is informational (issues shown here will not fail the PR).
API leaks ✔️
The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
Package | Leaked API symbols |
---|
License Headers ✔️
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// 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.
Files |
---|
no missing headers |
All source files should start with a license header.
**Example**: ```dart final myMap = { 'foo': 42, 'bar': -1, 'foobar': 21, }; // myMap without negative values myMap.entries.whereValue((v) => v >= 0).toMap(); // myMap, but only keys that start with 'foo' myMap.entries.whereKey((k) => k.startsWith('foo')).toMap(); ```
413cb2f
to
672e51a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it.
I'm not awfully happy about people working on MapEntry
s in general, but this seems to be withing reason (it's not just treating them as arbitrary pairs).
/// Creates a new lazy [Iterable] with all elements whose [MapEntry.value] | ||
/// satisfy the predicate [test]. | ||
Iterable<MapEntry<K, V>> whereValue(bool Function(V) test) => | ||
where((e) => test(e.value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Too bad where
is taken, so it can't be where({bool Function(K)? key, bool Function(V)? value})
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I feel the same with .map
.
But I wouldn't make where({bool Function(K)? key, bool Function(V)? value})
.
I would make: where(bool Function(K, V) test)
, ignoring a parameter in a closure is not that bad.
Maybe, we should consider adding:
wherePair(bool Function(K, V) test)
mapPair<T>(T Function(K, V) toElement)
We could consider adding such extension methods to:
Iterable<MapEntry<K, V>>
, and,Iterable<(A, B)>
.
But that seems outside the scope of this PR.
And it's entirely possible that a language feature providing pattern matching in the signature of a closure is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe whereEntry
/mapEntry
/anyEntry
/everyEntry
with an X Function(K, V)
argument. (Don't say "pair", it's not — just — a pair! It's a key-and-value.)
Some of those (not whereEntry
) could be extensions to Map<K,V>
too. (Not saying they should, but they could.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (Rubberstamp!)
@@ -1,5 +1,5 @@ | |||
name: collection | |||
version: 1.19.1 | |||
version: 1.19.1-wip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be 1.20.0, unless 1.19.0 hasn't been released yet.
(Adds new feature ⇒ minor version increment.)
Revisions updated by `dart tools/rev_sdk_deps.dart`. core (https://github.com/dart-lang/core/compare/4b62792..1156cfe): 1156cfe4 2024-11-06 Jacob MacDonald Use `values` iterator and `update` in map equality/hash (dart-lang/core#718) 9ab5a189 2024-11-05 Jacob MacDonald add a basic benchmark for DeepCollectionEquality (dart-lang/core#717) 9e379158 2024-11-05 Jonas Finnemann Jensen Introduce `IterableMapEntryExtension` for use with `Map.entries`. (dart-lang/core#715) dartdoc (https://github.com/dart-lang/dartdoc/compare/5168f81..24c2a96): 24c2a966 2024-11-04 dependabot[bot] Bump the github-actions group across 1 directory with 4 updates (dart-lang/dartdoc#3922) http (https://github.com/dart-lang/http/compare/8db0d0a..03ced4d): 03ced4d 2024-11-06 Brian Quinlan Upgrade flutter_http_example to cupertino_http (dart-lang/http#1393) df59bac 2024-11-05 Brian Quinlan Release package:cupertino_http 2.0.1 (dart-lang/http#1400) 0544e1f 2024-11-05 Brian Quinlan Fix a bug where cupertino_http did not work on iOS<17. (dart-lang/http#1399) sse (https://github.com/dart-lang/sse/compare/1b02011..befbd6d): befbd6d 2024-11-04 dependabot[bot] Bump actions/checkout from 4.2.0 to 4.2.2 in the github-actions group (dart-archive/sse#118) Change-Id: I2b4ebfe2f56f9478c7e89cd2d3e50485ae44caa0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393943 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Devon Carew <[email protected]> Auto-Submit: Devon Carew <[email protected]>
These utilities could often be useful when working with maps. We could also put this into a different utility package.
Example:
I'm tempted to also suggest:
But the name is a bit long.
mapKV
is lovely short, but probably too ugly.When doing
.map
overIterable<MapEntry>
you generally don't want to write.map((entry) => entry.key
.