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.*
import arrow.core.*
Id("hello")
// Id(value=hello)
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
val id: Id<Int> = Id.just(3)
id.map{it + 3}
// Id(value=6)