The implementation of the Semigroup has less clauses, but I think it is also more descriptive since the code "explains" how the semigroup works whereas in the original version it exhaustively enumerated over the items, but without explaining the rules of the semigroup.
Likely the implementation is also slightly more memory efficient, since we return the SetTo _ parameter, not constructing a new equivalent one. The implementation is also more lazy, since we never evaluate the first parameter here. If the second item is thus Default or SetTo _ we will never evaluate the first parameter.
A test is created to check if the implementation is equivalent to the old Semigroup instance.
The implementation of the
Semigroup
has less clauses, but I think it is also more descriptive since the code "explains" how the semigroup works whereas in the original version it exhaustively enumerated over the items, but without explaining the rules of the semigroup.Likely the implementation is also slightly more memory efficient, since we return the
SetTo _
parameter, not constructing a new equivalent one. The implementation is also more lazy, since we never evaluate the first parameter here. If the second item is thusDefault
orSetTo _
we will never evaluate the first parameter.A test is created to check if the implementation is equivalent to the old
Semigroup
instance.