arrow-typeclasses / arrow.typeclasses / Monoidal

Monoidal

interface Monoidal<F> : Semigroupal<F>

The Monoidal type class adds an identity element to the Semigroupal type class by defining the function identity.

identity returns a specific identity Kind<F, A> value for a given type F and A.

This type class complies with the following law:

fa.product(identity) == identity.product(fa) == identity

In addition, the laws of the Semigroupal type class also apply.

Currently, Monoidal instances are defined for Option, ListK, SequenceK and SetK.

Examples

The following examples show the identity elements for the already defined Monoidal instances:


import arrow.core.Option
import arrow.core.extensions.option.monoidal.monoidal

fun main(args: Array<String>) {
  val result =
  //sampleStart
  Option.monoidal().run {
    identity<Any>()
  }
  //sampleEnd
  println(result)
}

import arrow.data.ListK
import arrow.data.extensions.listk.monoidal.monoidal

fun main(args: Array<String>) {
  val result =
  //sampleStart
  ListK.monoidal().run {
    identity<Any>()
  }
  //sampleEnd
  println(result)
}

import arrow.data.SetK
import arrow.data.extensions.setk.monoidal.monoidal

fun main(args: Array<String>) {
  val result =
  //sampleStart
  SetK.monoidal().run {
    identity<Any>()
  }
  //sampleEnd
  println(result)
}

import arrow.data.SequenceK
import arrow.data.extensions.sequencek.monoidal.monoidal

fun main(args: Array<String>) {
  val result =
  //sampleStart
  SequenceK.monoidal().run {
    identity<Any>()
  }
  //sampleEnd
  println(result)
}

Functions

identity abstract fun <A> identity(): Kind<F, A>
Given a type A, create an “identity” for a F value.

Inherited Functions

product abstract fun <A, B> Kind<F, A>.product(fb: Kind<F, B>): Kind<F, Tuple2<A, B>>
Multiplicatively combine F and F into F<Tuple2<A, B>>
times open operator fun <A, B> Kind<F, A>.times(fb: Kind<F, B>): Kind<F, Tuple2<A, B>>
Add support for the * syntax

Extension Functions

const fun <A> A.const(): Const<A, Nothing>

Type Class Hierarchy