arrow-core-data / arrow.core / Id
@higherkind data class Id<out A>
The identity monad can be seen as the ambient monad that encodes the effect of having no effect.
It is ambient in the sense that plain pure values are values of Id
.
import arrow.core.Id
fun getId() =
//sampleStart
Id("hello")
//sampleEnd
fun main() {
println(getId())
}
Using this type declaration, we can treat our Id type constructor as a Monad
and as a Comonad
.
The just
method, which has type A -> Id<A>
just becomes the identity function. The map
method
from Functor
just becomes function application.
import arrow.core.Id
//sampleStart
fun idPlusThree(value: Int) =
Id.just(value)
.map { it + 3 }
//sampleEnd
fun main() {
val value = 3
println("idPlusThree($value) = ${idPlusThree(value)}")
}
<init> | The identity monad can be seen as the ambient monad that encodes the effect of having no effect. It is ambient in the sense that plain pure values are values of Id .Id(value: A) |
ap | fun <B> ap(ff: <ERROR CLASS><(A) -> B>): Id <B> |
coflatMap | fun <B> coflatMap(f: (<ERROR CLASS><A>) -> B): Id <B> |
equals | fun equals(other: Any ?): Boolean |
extract | fun extract(): A |
flatMap | fun <B> flatMap(f: (A) -> <ERROR CLASS><B>): Id <B> |
foldLeft | fun <B> foldLeft(initial: B, operation: (B, A) -> B): B |
foldRight | fun <B> foldRight(initial: Eval <B>, operation: (A, Eval <B>) -> Eval <B>): Eval <B> |
hashCode | fun hashCode(): Int |
map | fun <B> map(f: (A) -> B): Id <B> |
just | fun <A> just(a: A): Id <A> |
tailRecM | tailrec fun <A, B> tailRecM(a: A, f: (A) -> <ERROR CLASS>< Either <A, B>>): Id <B> |
select | fun <A, B> Id < Either <A, B>>.select(f: <ERROR CLASS><(A) -> B>): Id <B> |