higorlapa / result Goto Github PK
View Code? Open in Web Editor NEWResult package for dart
License: MIT License
Result package for dart
License: MIT License
I think the title covers it pretty well but I will elaborate a bit further.
I am currently using version 3.1.0 of the package and was about to migrate to 4.0.0 when I realized, that the AsyncResult
typedef along with its extensions was gone. I am heavily using this alias and its extension for a project of mine and just wanted to ask, why this feature was removed? Because in my opinion it does not conflict with the simplicity of the project.
I hope I did not come across as rude, I genuinely am just interested!
Hi,
How do we write test case for Result. I cant access the success or error value in test case. It always fail in
expectLater(response.tryGetSuccess(), true);
test('Give login request When login Then return success', () async {
when(mockSettingRepository.addToBox<String>(accessTokenKey,loginResponse.accessToken))
.thenAnswer((_) async => true);
when(mockLoginRepository.login(loginRequest))
.thenAnswer((_) async => loginResponse);
final loginService = LoginService(mockLoginRepository, mockSettingRepository);
final Result<bool, Failure> response = await loginService.login(loginRequest);
expect(response.isSuccess(), true);
expectLater(response.tryGetSuccess(), true);
expect(response, isA<Result>());
verify(mockLoginRepository.login(loginRequest)).called(1);
});
If we are sure that there is no error we have to do something like this:
final userResult =
await _apiAuthService.login(email: email, password: password);
if (userResult case Error(:final error)) {
// handle error
}
final user = userResult.tryGetSuccess()!;
But I think that it would be better with something like this:
final userResult =
await _apiAuthService.login(email: email, password: password);
if (userResult case Error(:final error)) {
// handle error
}
final user = userResult.unwrap();
Any chance of flipping the types to improve the readability?
Currently, it reads like "result of an exception".
But when you flip the types to Result<Expected, Error>
it becomes "result of something I expect".
Hello dev:
/// Return [Left] if the function throws an error.
/// Otherwise return [Right].
final tryCatch = Either.tryCatch(
() => int.parse('invalid'),
(e, s) => 'Error: $e',
);
Thanks.
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.