-
Notifications
You must be signed in to change notification settings - Fork 36
Introduce IterableMapEntryExtension for use with Map.entries.
#715
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -914,6 +914,33 @@ extension IterableIterableExtension<T> on Iterable<Iterable<T>> { | |
| }; | ||
| } | ||
|
|
||
| /// Extension on iterables of [MapEntry]. | ||
| /// | ||
| /// An [Iterable<MapEntry>] is obtained using [Map.entries], these extensions | ||
| /// make it easy to work on a [Map] as a list of pairs. | ||
| extension IterableMapEntryExtension<K, V> on Iterable<MapEntry<K, V>> { | ||
| /// Creates a new lazy [Iterable] with all elements whose [MapEntry.key] | ||
| /// satisfy the predicate [test]. | ||
jonasfj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Iterable<MapEntry<K, V>> whereKey(bool Function(K) test) => | ||
| where((e) => test(e.key)); | ||
|
|
||
| /// 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)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Too bad
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I feel the same with But I wouldn't make Maybe, we should consider adding:
We could consider adding such extension methods to:
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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
|
|
||
| /// Create an new lazy [Iterable] with [MapEntry.key] from all elements. | ||
jonasfj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
jonasfj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Iterable<K> get keys => map((e) => e.key); | ||
|
|
||
| /// Create an new lazy [Iterable] with [MapEntry.value] from all elements. | ||
jonasfj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Iterable<V> get values => map((e) => e.value); | ||
|
|
||
| /// Create a [Map] from all elements. | ||
jonasfj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// This is a short-hand for [Map.fromEntries]. | ||
| Map<K, V> toMap() => Map.fromEntries(this); | ||
jonasfj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// Extensions that apply to iterables of [Comparable] elements. | ||
| /// | ||
| /// These operations can assume that the elements have a natural ordering, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| name: collection | ||
| version: 1.19.1 | ||
| version: 1.19.1-wip | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| description: >- | ||
| Collections and utilities functions and classes related to collections. | ||
| repository: https://github.com/dart-lang/core/tree/main/pkgs/collection | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.