google / dart-basics Goto Github PK
View Code? Open in Web Editor NEWA Dart library containing convenient extension methods on basic Dart objects.
Home Page: https://pub.dev/packages/basics
License: BSD 3-Clause "New" or "Revised" License
A Dart library containing convenient extension methods on basic Dart objects.
Home Page: https://pub.dev/packages/basics
License: BSD 3-Clause "New" or "Revised" License
I created a new project and used the basic: ^0.4.0
and with flutter run
got below result / error
Because every version of flutter_test from sdk depends on quiver 2.0.5 and every version of basics depends on quiver ^2.1.2+1, flutter_test from sdk is incompatible with basics.
So, because DemoApp depends on both basics ^0.4.0 and flutter_test any from sdk, version solving failed.
If I comment this dependency and do flutter run
, it works perfectly.
also below is output for flutter doctor -v
flutter doctor -v
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E287, locale en-GB)
• Flutter version 1.12.13+hotfix.9 at /Library/flutter
• Framework revision f139b11009 (5 weeks ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/dragonar/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4, Build version 11E146
• CocoaPods version 1.9.1
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] VS Code (version 1.44.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.10.1
[✓] Connected device (1 available)
• iPhone 11 Pro Max • 2BERFC15-950E-48GB-B556-F6797HH49DEF • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-4 (simulator)
• No issues found!
Is the null-safe version going to be published soon?
Before the null safety release, the package relied on quiver for some APIs. For example isBlank
was would call https://pub.dev/documentation/quiver/latest/quiver.strings/isBlank.html. This allowed passing a nullable string as isBlank
would return true if it was null or only contained whitespace characters. With this PR from @zdg2102 to migrate the null safety this API other similar ones no longer accept nullable strings. This mean previously when developers were able to write
if(someString.isBlank) {
...
}
they now need to write
if(someString?.isBlank ?? true) {
...
}
I wanted to ask if this is an intentional change as this makes the library less useful in dealing with scenarios like this. Seems like something that perhaps should've been documented in the changelog as well but there's no mention of this. No unit tests exist for this API to have caught this change too
I currently have code like this:
final optimalFoo = foos.minBy((foo) {
print('Calculating error score of $foo.');
return expensiveErrorScoreComputation(foo);
});
And for a list of 5 foos, it prints this:
Calculating error score of Foo0.
Calculating error score of Foo1.
Calculating error score of Foo1.
Calculating error score of Foo2.
Calculating error score of Foo1.
Calculating error score of Foo3.
Calculating error score of Foo1.
Calculating error score of Foo4.
The score of the candidate is re-computed again and again. That's because the implementation of minBy
is pretty naively implemented. I think it should be more optimized.
Add me as a maintainer and I'm happy to take care of it...I have a lot of experience!
Dealing with MapEntry
s is cumbersome:
final differentChunks = _newChunks.entries
.where((entry) => entry.value.isDirty)
.where((entry) => entry.value.data != _originalChunks[entry.key])
.toList();
Extension methods for whereKey
, whereValue
and whereKeyValue
on Iterable<MapEntry<K, V>>
could make this much more readable:
final differentChunks = _newChunks.entries
.whereValue((chunk) => chunk.isDirty)
.whereKeyValue((index, chunk) => chunk.data != _originalChunks[index])
.toList();
Code context: I have a
List
of data chunks and aList
of possibly changed data chunks, which have anisDirty
property to indicate whether some values were changed. It's possible that some data is changed and then changed back again, so to get aList
of only those chunks that are actually different than the other, I first filter by theisDirty
property and only then do the expensive comparison of actual values.
It would be great to be able to get a range from a (possibly infinite) Iterable
, similar to List
's sublist
:
var a = Iterable.generate(100, (i) => i).range(5, 20);
extension LazyRange<T> on Iterable<T> {
Iterable<T> range(int from, int to) => skip(from).take(to - from);
}
When I added MapBasics.get
, I didn't give significant thought to NNBD. Now that I have, it's become clear that it will be broken, and it's unclear what we should do about it:
We could make MapBasics.get
return V?
, just like Map.operator []
. This is the easiest, but it seems weirdly non-optimal since I made MapBasics.get
take an optional default value:
final map = <String, int>{};
int x = map.get('foo', 0); // Would fail to compile.
and people would have to use map.get(...)!
.
We could make MapBasics.get
return V
. I think that would prevent the default value from ever being optional, even if V
is nullable. That's a bit less convenient but probably would be acceptable. However, it also would prevent using map.get(key, null)
if V
is non-nullable, forcing people to use map[key]
instead.
If Dart supported overloading, we could have the best of both worlds by doing V? get(K key)
and V get(K key, V defaultValue)
. Alas. The next best thing would be to split MapBasics.get
into two separately named methods. (I don't yet have any name suggestions.)
I am not an expert on the nuances of Dart generics, but possibly MapBasics.get
could be generic with a parameterized return type. Ideally it'd be deducible from the union of V
and the type of the default value (which either should be V
or V?
), but I am not optimistic that there is any magic workaround.
Right now iterable_basics.dart
has some methods that return Optional
s. Once Dart has non-nullable types by default, we should return nullable types instead of Optionals.
NNBD = Non-null by default.
Follow-up to #17
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.