trait
Associative[A] extends AnyRef
Abstract Value Members
-
abstract
def
combine(l: ⇒ A, r: ⇒ A): A
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
final
def
==(arg0: Any): Boolean
-
final
def
asInstanceOf[T0]: T0
-
def
clone(): AnyRef
-
-
-
def
finalize(): Unit
-
final
def
getClass(): Class[_]
-
def
hashCode(): Int
-
final
def
intersperse(middle: A): Associative[A]
-
final
def
isInstanceOf[T0]: Boolean
-
def
multiplyOption(n: Int)(a: A): Option[A]
-
-
final
def
notify(): Unit
-
final
def
notifyAll(): Unit
-
final
def
repeat(a: A)(n: Int): A
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
-
def
toString(): String
-
final
def
wait(): Unit
-
final
def
wait(arg0: Long, arg1: Int): Unit
-
final
def
wait(arg0: Long): Unit
The
Associative[A]
type class describes an associative binary operator for a typeA
. For example, addition for integers, and string concatenation for strings.Associative
is at the top of the hierarchy for abstracting over operations to combine types because while there are some operations that are not associative but do obey other laws, it is generally difficult to combine more than two values in interesting ways with these operators, and thus to build solutions to more complicated problems out of solutions to simpler ones.For example, the mean of two numbers is an operation that is commutative but not associative. However, the lack of associativity is an indication that we can't combine the means of multiple values in an interesting way with this definition. If we attempt to take the mean of three values we always place twice as much weight on one number as the others, which is rarely what we want.
If we instead define this operation using a
StatsCounter
object then means can be combined in ways that are associative, commutative, and have an identity element, supporting much more interesting modes of composition.