What is MonoidAggregator in Algebird

292 views Asked by At

I don't find any documention about MonoidAggregator. What is it for ?

An example of its use:

MultiAggregator(
   ...,
   Aggregator.forall[T](_.use)).andThenPresent(...)
   ...,
)

forAll return a MonoidAggregator.

Whould it be roughly the same as setting the prepare to return the zero if _use == false ?

1

There are 1 answers

0
Oscar Boykin On

A MonoidAggregator is just an Aggregator that has an underlying Monoid rather than Semigroup. This means you can apply it to an empty sequence and not get an exception.

So, basically a monoid aggregator is:

trait Aggregator[A, B, C] {
  def prepare(a: A): B
  def semigroup: Semigroup[B]
  def present(b: B): C
}

trait MonoidAggregator[A, B, C] extends Aggregator[A, B, C] {
  def prepare(a: A): B
  def monoid: Monoid[B]
  final def semigroup: Semigroup[B] = monoid
  def present(b: B): C
}