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

Non-commutative operations in foldRight #127

Open
t-rutten opened this issue Apr 20, 2023 · 0 comments
Open

Non-commutative operations in foldRight #127

t-rutten opened this issue Apr 20, 2023 · 0 comments
Assignees

Comments

@t-rutten
Copy link

The behavior of Semigroup.foldRight and Monoid.foldRight is different for non-commutative operations. For monoids, we have:

Lazy<String> resultMonoid = Monoid.monoid(String::concat, "").foldRight("", Arrays.asList("1", "2", "3", "4"));
resultMonoid.value()
// "1234"

For semigroups:

Lazy<String> resultSemigroup = ((Semigroup<String> String::concat)).foldRight("", Arrays.asList("1", "2", "3", "4"));
resultSemigroup.value()
// "4321"

It appears the order of arguments is reversed inside fmap of the semigroup implementation (source). Is there motivation for this difference between foldRight in the two algebras?

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