Workex.Aggregate protocol

Specifies the protocol used by Workex behaviour to aggregate incoming messages.

Summary

Functions

Adds the new item to the aggregate

Removes the oldest item from the collection

Returns the number of aggregated items

Produces an aggregated value from all collected items

Types

t :: term
value :: any

Functions

add(aggregate, message)

Specs

add(t, any) :: t

Adds the new item to the aggregate.

remove_oldest(aggregate)

Specs

remove_oldest(t) :: t

Removes the oldest item from the collection.

Sometimes it doesn't make sense to implement this function, for example when the aggregation doesn't guarantee or preserve ordering. In such cases, just raise from the implementation, and document that the implementation can't be used with the replace_oldest option.

size(aggregate)

Specs

size(t) :: non_neg_integer

Returns the number of aggregated items.

This function is invoked frequently, so be sure to make the implementation fast.

value(aggregate)

Specs

value(t) :: {value, t}

Produces an aggregated value from all collected items.

The returned tuple contains aggregated items, and the new instance that doesn't contain those items.