- Why is the property of associativity essential for the monoid to be useful in a distributed setup?
In a distributed setup, we're usually talking about folding and reusing datasets with parts of the data being processed by different computers. Monoidal operations are applied on remote machines. Regardless of the order in which they were sent from the master machine, network delays, different load patterns, and hardware settings will influence the order in which they will be returned. It is important to be able to apply an operation on the intermediate results already at hand without waiting for the first operations to complete.
- Implement a monoid for Boolean under OR.
The implementation is as follows:
implicit val booleanOr: Monoid[Boolean] = new Monoid[Boolean] {
override def identity: Boolean = false
override def op(l: Boolean, r: Boolean): Boolean = l |...