Machine learning and software projects are what I code
avdosev / either_dart Goto Github PK
View Code? Open in Web Editor NEWEither class for Dart or Flutter projects.
Home Page: https://pub.dev/packages/either_dart
License: MIT License
Either class for Dart or Flutter projects.
Home Page: https://pub.dev/packages/either_dart
License: MIT License
Machine learning and software projects are what I code
I'm using either_dart in getter-setter.
But I'm stuck while adding data to the list. I want to add data to the list using pagination So can you please guide me that how can i add data to the list?
Here is my code,
Either<List<NotificationResponseData>, Exception> _notificationData = Right(SuccessResultException());
Either<List<NotificationResponseData>, Exception> get notificationData => _notificationData;
set notificationData(Either<List<NotificationResponseData>, Exception> value) {
_notificationData = value;
// _notificationData.fold((left) => value.left, (right) => value.right);
notifyListeners();
}
In 1.0.0 the Either class was sealed. This breaked the generated mocking code for unit tests.
Is there a need for this class to be sealed?
We are forced to remain on version 0.4.0 - please reconsider sealing.
Thank you
either_dart/lib/src/future_extension.dart
Lines 57 to 59 in 06b4361
I am quite new to dart so I may be wrong here (that's why I am creating an issue rather then pull request) but shouldn't fnL
and fnR
return FutureOr<T>
instead of T
?
Future<T> fold<T>(FutureOr<T> Function(L left) fnL, FutureOr<T> Function(R right) fnR) {
return this.then((either) => either.fold(fnL, fnR));
}
This is what this.then()
actually expects and it would allow us to do something like this:
bool success = await getStatusAsync()
.fold(
(error) async {
await saveErrorAsync(error);
return false;
},
(status) async {
await saveStatusAsync(status);
return true;
},
);
(it's just and example and my usecase is actually quite different but I also need to fold both left and right to different futures of the same type)
Any guidelines how to migrate existing code?
https://dart.dev/language/class-modifiers#sealed
Admittedly I haven't dug too deep here - but seems like a sealed
annotation would be a nice addition for this lib.
Might need to be a separate package to maintain compatibility with Dart < 3.0.
Happy to take a stab at it at some point in the next week or two if you'd like!
test('should be same', () {
final x = Left('test');
final z = Left('test');
expect(x, z);
});
Result:
Expected: <Instance of 'Left<String, dynamic>'>
Actual: <Instance of 'Left<String, dynamic>'>
/// Constructs a new [Either] from a function that might throw
static Either<L, R> tryCatch<L, R, Err extends Object>(
L Function(Err err) onError, R Function() fnR) {
try {
return Right(fnR());
} on Err catch (e) {
return Left(onError(e));
}
}
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.