Associative

zio.prelude.Associative
See theAssociative companion object
trait Associative[A]

The Associative[A] type class describes an associative binary operator for a type A. 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.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait AssociativeEqual[A]
trait CommutativeEqual[A]
trait EqualIdempotent[A]
trait EqualIdentity[A]
trait EqualInverse[A]
trait Commutative[A]
trait Idempotent[A]
trait Identity[A]
trait PartialInverse[A]
trait Inverse[A]
Show all
Self type

Members list

Value members

Abstract methods

def combine(l: => A, r: => A): A
Implicitly added by EitherAssociative
def combine(l: => A, r: => A): A
def identity: A
Implicitly added by MapIdentity

The identity element.

The identity element.

Attributes

def identity: A
Implicitly added by OptionIdentity

The identity element.

The identity element.

Attributes

Concrete methods

final def intersperse(middle: A): Associative[A]
Implicitly added by EitherAssociative
final def intersperse(middle: A): Associative[A]
def multiplyOption(n: Int)(a: A): Option[A]
Implicitly added by EitherAssociative
def multiplyOption(n: Int)(a: A): Option[A]
final def repeat(a: A)(n: Int): A
Implicitly added by EitherAssociative
final def repeat(a: A)(n: Int): A

Inherited methods

final def intersperse(middle: A): Associative[A]
Implicitly added by MapIdentity

Attributes

Inherited from:
Associative
final def intersperse(middle: A): Associative[A]
Implicitly added by OptionIdentity

Attributes

Inherited from:
Associative
final def repeat(a: A)(n: Int): A
Implicitly added by MapIdentity

Attributes

Inherited from:
Associative
final def repeat(a: A)(n: Int): A
Implicitly added by OptionIdentity

Attributes

Inherited from:
Associative

Inherited and Abstract methods

def combine(l: => A, r: => A): A
Implicitly added by MapIdentity

Attributes

Inherited from:
Associative
def combine(l: => A, r: => A): A
Implicitly added by OptionIdentity

Attributes

Inherited from:
Associative