Skip to content

Non-commutative operations in foldRight #127

@t-rutten

Description

@t-rutten

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?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions