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

Confusing Documentation for foldLeft and foldRight Methods in Either Class #152

Closed
hanmango-o opened this issue May 21, 2024 · 2 comments · Fixed by #157
Closed

Confusing Documentation for foldLeft and foldRight Methods in Either Class #152

hanmango-o opened this issue May 21, 2024 · 2 comments · Fixed by #157

Comments

@hanmango-o
Copy link

hanmango-o commented May 21, 2024

Description

The foldLeft and foldRight methods in the �either.dart have identical comments, which can be misleading because these methods perform different operations.

Current Documentation

/// Return the result of `f` called with `b` and the value of [Right].
/// If this [Either] is [Left], return `b`.
@Override
C foldRight<C>(C b, C Function(C acc, R b) f);

/// Return the result of `f` called with `b` and the value of [Right].
/// If this [Either] is [Left], return `b`.
@Override
C foldLeft<C>(C b, C Function(C acc, R b) f) =>
    foldMap<Endo<C>>(dualEndoMonoid(), (b) => (C c) => f(c, b))(b);

Issue

The comments for foldLeft and foldRight are identical, even though these methods should have different descriptions because they perform different operations:

  • foldLeft: Folds the elements from left to right.

  • foldRight: Folds the elements from right to left.

Suggested Documentation

To avoid confusion, the comments should reflect the distinct behaviors of these methods.

/// This method folds the value from right to left.
/// 
/// Return the result of `f` called with `b` and the value of [Right].
/// If this [Either] is [Left], return `b`.
@Override
C foldRight<C>(C b, C Function(C acc, R b) f);

/// This method folds the value from left to right.
///
/// Return the result of `f` called with `b` and the value of [Right].
/// If this [Either] is [Left], return `b`.
@Override
C foldLeft<C>(C b, C Function(C acc, R b) f) =>
    foldMap<Endo<C>>(dualEndoMonoid(), (b) => (C c) => f(c, b))(b);

Thanks for your attention to this issue and for your continuous efforts. I always appreciate using this library!

@JRParreno
Copy link

bro do you have any idea how to get the right value only?

@HasanAlqaisi
Copy link

bro do you have any idea how to get the right value only?

final either = Either<String, int>.of(10);
if (either case Right(value: final value)) {
  /// `value` from [Either] type `int`
}

@SandroMaglione SandroMaglione linked a pull request Nov 7, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants