Code Monkey home page Code Monkey logo

result's People

Contributors

eronildo avatar higorlapa avatar jacobaraujo7 avatar jodeveloper avatar nerdfaisal404 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

result's Issues

[question]: Why was AsyncResult removed?

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!

Unit Test

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);


  });

An Unwrap method like in rust would be nice

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();

Flip the types

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".

[Enhanceman] add `tryCatch` function?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.