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

Functions

ap fun <B> ap(ff: IdOf<(A) -> B>): Id<B>
coflatMap fun <B> coflatMap(f: (IdOf<A>) -> B): Id<B>
equals fun equals(other: Any?): Boolean
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>
hashCode fun hashCode(): Int
map fun <B> map(f: (A) -> B): Id<B>

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

const fun <A> A.const(): Const<A, Nothing>
fix fun <A> IdOf<A>.fix(): Id<A>
invalid fun <E> E.invalid(): Validated<E, Nothing>
invalidNel fun <E> E.invalidNel(): ValidatedNel<E, Nothing>
left fun <A> A.left(): Either<A, Nothing>
leftIor fun <A> A.leftIor(): Ior<A, Nothing>
nel fun <A> A.nel(): NonEmptyList<A>
right fun <A> A.right(): Either<Nothing, A>
rightIfNotNull fun <A, B> B?.rightIfNotNull(default: () -> A): Either<A, B>
Returns Either.Right if the value of type B is not null, otherwise the specified A value wrapped into an Either.Left.
rightIor fun <A> A.rightIor(): Ior<Nothing, A>
select fun <A, B> Id<Either<A, B>>.select(f: IdOf<(A) -> B>): Id<B>
some fun <A> A.some(): Option<A>
success fun <A> A.~~success~~(): Try<A>
toOption fun <T> T?.toOption(): Option<T>
toT infix fun <A, B> A.toT(b: B): Tuple2<A, B>
valid fun <A> A.valid(): Validated<Nothing, A>
validNel fun <A> A.validNel(): ValidatedNel<Nothing, A>
value fun <A> IdOf<A>.value(): A