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?
The behavior of
Semigroup.foldRightandMonoid.foldRightis different for non-commutative operations. For monoids, we have:For semigroups:
It appears the order of arguments is reversed inside
fmapof the semigroup implementation (source). Is there motivation for this difference betweenfoldRightin the two algebras?