Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

result doesn't return anything #9

Open
mariomka opened this issue Mar 6, 2022 · 1 comment
Open

result doesn't return anything #9

mariomka opened this issue Mar 6, 2022 · 1 comment

Comments

@mariomka
Copy link

mariomka commented Mar 6, 2022

Maybe I'm wrong but reading result documentation seems that it will return a new Result applying the appropriate function but it returns void. Something like a fold method.

/// Returns a new value of [Result] from closure
/// either a success or a failure.

If it isn't the expected behavior of the result, can you consider adding a fold method? Implementation should be like this:

Result<U, E> fold<U, E>(U Function(S) success, E Function(F) failure) {
  if (isSuccess) {
    final left = this as Success<S, F>;
    return Success(success(left.value));
  }

  final right = this as Failure<S, F>;
  return Failure(failure(right.value));
}
@slawekkrol
Copy link

You can check Pull request with fold method, I already created this one:
https://github.com/slawekkrol/dart_result_type/tree/feature/fold_function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants