Monoid

trait Monoid[F] extends Semigroup[F]

Provides an identity element (zero) to the binary append operation in scalaz.Semigroup, subject to the monoid laws.

Example instances:

  • Monoid[Int]: zero and append are 0 and Int#+ respectively
  • Monoid[List[A]]: zero and append are Nil and List#++ respectively

References:

See also
Companion
object
trait Semigroup[F]
class Object
trait Matchable
class Any

Type members

Classlikes

trait MonoidLaw extends SemigroupLaw

Monoid instances must satisfy scalaz.Semigroup.SemigroupLaw and 2 additional laws:

Monoid instances must satisfy scalaz.Semigroup.SemigroupLaw and 2 additional laws:

  • '''left identity''': forall a. append(zero, a) == a
  • '''right identity''' : forall a. append(a, zero) == a

Inherited classlikes

A semigroup in type F must satisfy two laws:

A semigroup in type F must satisfy two laws:

  • '''closure''': ∀ a, b in F, append(a, b) is also in F. This is enforced by the type system.
  • '''associativity''': ∀ a, b, c in F, the equation append(append(a, b), c) = append(a, append(b , c)) holds.
Inherited from
Semigroup

Value members

Abstract methods

def zero: F

The identity element for append.

The identity element for append.

Concrete methods

final
def applicative: Applicative[[α] =>> F]

A monoidal applicative functor, that implements point and ap with the operations zero and append respectively. Note that the type parameter α in Applicative[λ[α => F]] is discarded; it is a phantom type. As such, the functor cannot support scalaz.Bind.

A monoidal applicative functor, that implements point and ap with the operations zero and append respectively. Note that the type parameter α in Applicative[λ[α => F]] is discarded; it is a phantom type. As such, the functor cannot support scalaz.Bind.

final
def category: Category[[α, β] =>> F]

Every Monoid gives rise to a scalaz.Category, for which the type parameters are phantoms.

Every Monoid gives rise to a scalaz.Category, for which the type parameters are phantoms.

Note

category.monoid = this

final
def ifEmpty[B](a: F)(t: => B)(f: => B)(implicit eq: Equal[F]): B
def isMZero(a: F)(implicit eq: Equal[F]): Boolean

Whether a == zero.

Whether a == zero.

def multiply(value: F, n: Int): F

For n = 0, zero For n = 1, append(zero, value) For n = 2, append(append(zero, value), value)

For n = 0, zero For n = 1, append(zero, value) For n = 2, append(append(zero, value), value)

final
def onEmpty[A, B](a: F)(v: => B)(implicit eq: Equal[F], mb: Monoid[B]): B
final
def onNotEmpty[B](a: F)(v: => B)(implicit eq: Equal[F], mb: Monoid[B]): B

Inherited methods

def append(f1: F, f2: => F): F

The binary operation to combine f1 and f2.

The binary operation to combine f1 and f2.

Implementations should not evaluate the by-name parameter f2 if result can be determined by f1.

Inherited from
Semigroup
final
def apply: Apply[[α] =>> F]

An scalaz.Apply, that implements ap with append. Note that the type parameter α in Apply[λ[α => F]] is discarded; it is a phantom type. As such, the functor cannot support scalaz.Bind.

An scalaz.Apply, that implements ap with append. Note that the type parameter α in Apply[λ[α => F]] is discarded; it is a phantom type. As such, the functor cannot support scalaz.Bind.

Inherited from
Semigroup
final
def compose: Compose[[α, β] =>> F]

Every Semigroup gives rise to a scalaz.Compose, for which the type parameters are phantoms.

Every Semigroup gives rise to a scalaz.Compose, for which the type parameters are phantoms.

Note

compose.semigroup = this

Inherited from
Semigroup
def multiply1(value: F, n: Int): F

For n = 0, value For n = 1, append(value, value) For n = 2, append(append(value, value), value)

For n = 0, value For n = 1, append(value, value) For n = 2, append(append(value, value), value)

The default definition uses peasant multiplication, exploiting associativity to only require O(log n) uses of append

Inherited from
Semigroup

Concrete fields

Inherited fields