arrow-core / arrow.core.extensions.set.semigroupal / Set / semigroupal
fun ~~semigroupal~~():
SetKSemigroupal
Deprecated: Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0
The Semigroupal type class for a given type F
can be seen as an abstraction over the cartesian product.
It defines the function product.
The product function for a given type F
, A
and B
combines a Kind<F, A>
and a Kind<F, B>
into a Kind<F, Tuple2<A, B>>
.
This function guarantees compliance with the following laws:
Semigroupals are associative under the bijection f = (a,(b,c)) -> ((a,b),c)
or f = ((a,b),c) -> (a,(b,c))
.
Therefore, the following laws also apply:
f((a.product(b)).product(c)) == a.product(b.product(c))
f(a.product(b.product(c))) == (a.product(b)).product(c)
Currently, Semigroupal instances are defined for Option, ListK, SequenceK and SetK.
import arrow.core.*
import arrow.core.extensions.setk.semigroupal.*
import arrow.core.*
fun main(args: Array<String>) {
val result =
//sampleStart
SetK.semigroupal()
//sampleEnd
println(result)
}
Here a some examples:
import arrow.core.Option
import arrow.core.extensions.option.semigroupal.semigroupal
fun main(args: Array<String>) {
val result =
//sampleStart
Option.semigroupal().run {
Option.just(1).product(Option.just(1))
}
//sampleEnd
println(result)
}
Semigroupal also has support of the *
syntax:
import arrow.core.Option
import arrow.core.extensions.option.semigroupal.semigroupal
fun main(args: Array<String>) {
val result =
//sampleStart
Option.semigroupal().run {
Option.just(2)
}
//sampleEnd
println(result)
}
The same applies to ListK, SequenceK and SetK instances:
import arrow.core.ListK
import arrow.core.extensions.listk.semigroupal.semigroupal
import arrow.core.k
fun main(args: Array<String>) {
val result =
//sampleStart
ListK.semigroupal().run {
listOf('a','b','c').k()
}
//sampleEnd
println(result)
}
Do you like Arrow?
✖