Comments (3)
Come to think of it, keys
and value
getters would also be very helpful.
I'd also be happy to file the PR.
from dart-basics.
This an interesting idea, personally I feel like it might make more sense as an extension of Map
rather than Iterable<MapEntry>
.
Would something like this be similarly useful?
void main() {
print({1: 2, 3: 5, 6: 7}.whereKey((key) => key % 2 == 0));
// Returns {6: 7}
}
extension Foo on Map {
Map whereKey<K, V>(bool Function(K) callback) {
return Map.fromEntries(this.entries.where((entry) => callback(entry.key)));
}
}
from dart-basics.
Yes, that would also solve what I'm trying to do. 👌
And because Map
already has keys
and values
getters, they wouldn't need to be implemented anymore.
It's not quite as efficient though, because it would convert the Map
into an Iterable<MapEntry>
for every step instead of just acting on the Iterable<MapEntry>
directly. This is especially noticeable if you would otherwise rely on the laziness of Iterable
s, for example by aborting after few elements: someReallyLargeMap.whereKey((key) => key.startsWith('blub')).values.take(5)
from dart-basics.
Related Issues (10)
- version solving failed HOT 3
- Add CI (travis?) HOT 3
- validate formatting and analyzer in CI HOT 1
- [NNBD] Remove "Optional"s in favor of nullable types when dart is NNBD HOT 3
- [NNBD] Rethink MapBasics.get HOT 1
- Get range from Iterable HOT 1
- Make minBy more efficient HOT 1
- Null safety HOT 4
- Question on changes on done as part of null safety release HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dart-basics.