arrow-core-data / arrow.core / Id / <init>

<init>

Id(value: 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)}")
}