Returns a new Commutative
instance that describes the same binary
operator but applied in reverse order.
Returns a new Commutative
instance that describes the same binary
operator but applied in reverse order. Since the operation is commutative
this instance is guaranteed to return the same results as the original
instance but one order of combination or the other may be more efficient
in certain cases.
The
Commutative
type class describes a binary operator for a typeA
that is both associative and commutative. This means thata1 <> a2
is equal toa2 <> a1
for all valuesa1
anda2
. Examples of commutative operations include addition for integers, but not concatenation for strings.Commutative operators are useful because combining values with a commutative operation results in the same value regardless of the order in which values are combined, allowing us to combine values in the order that is most efficient and allowing us to return determinate values even when the order of original values is indeterminate.