arrow-core-data / arrow.core / Id

Id

@higherkind data class Id<out A> : IdOf<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)}")
}

Constructors

<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)

Functions

ap fun <B> ap(ff: IdOf<(A) -> B>): Id<B>
coflatMap fun <B> coflatMap(f: (IdOf<A>) -> B): Id<B>
extract fun extract(): A
flatMap fun <B> flatMap(f: (A) -> IdOf<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>
map fun <B> map(f: (A) -> B): Id<B>
show fun show(SA: Show<A>): String
toString fun toString(): String

Companion Object Functions

just fun <A> just(a: A): Id<A>
tailRecM tailrec fun <A, B> tailRecM(a: A, f: (A) -> IdOf<Either<A, B>>): Id<B>

Extension Functions

altFold fun <T, F, A> Kind<T, A>.altFold(AF: Alternative<F>, FT: Foldable<T>): Kind<F, A>
altSum fun <T, F, A> Kind<T, Kind<F, A>>.altSum(AF: Alternative<F>, FT: Foldable<T>): Kind<F, A>
select fun <A, B> Id<Either<A, B>>.select(f: IdOf<(A) -> B>): Id<B>
value fun <A> IdOf<A>.value(): A

Do you like Arrow?

Arrow Org
<