arrow-core-data / arrow.core / AndThen
sealed class ~~AndThen~~<A, B> : (A) -> B,
AndThenOf
<A, B>
Deprecated: AndThen
is deprecated in favor of the function andThen
used to provide stack safe function composition.
AndThen wraps a function of shape (A) -> B
and can be used to do function composition.
It’s similar to arrow.core.andThen and arrow.core.compose and can be used to build stack safe
data structures that make use of lambdas. Usage is typically used for signature such as A -> Kind<F, A>
where
F
has a arrow.typeclasses.Monad instance i.e. StateT.flatMap.
As you can see the usage of AndThen is the same as `arrow.core.andThen except we start our computation by wrapping our function in AndThen.
import arrow.core.andThen
import arrow.core.AndThen
import arrow.core.extensions.list.foldable.foldLeft
fun main(args: Array<String>) {
//sampleStart
val f = (0..10000).toList()
.fold({ x: Int -> x + 1 }) { acc, _ ->
acc.andThen { it + 1 }
}
val f2 = (0..10000).toList()
.foldLeft(AndThen { x: Int -> x + 1 }) { acc, _ ->
acc.andThen { it + 1 }
}
//sampleEnd
println("f(0) = ${f(0)}, f2(0) = ${f2(0)}")
}
andThen | Compose a function to be invoked after the current function is invoked.fun <X> andThen(g: (B) -> X): AndThen <A, X> |
andThenF | fun <X> andThenF(right: AndThen <B, X>): AndThen <A, X> |
ap | fun <C> ap(ff: AndThenOf <A, (B) -> C>): AndThen <A, C> |
compose | Compose a function to be invoked before the current function is invoked.infix fun <C> compose(g: (C) -> A): AndThen <C, B> |
composeF | fun <X> composeF(right: AndThen <X, A>): AndThen <X, B> |
contramap | Alias for composefun <C> contramap(f: (C) -> A): AndThen <C, B> |
flatMap | fun <C> flatMap(f: (B) -> AndThenOf <A, C>): AndThen <A, C> |
invoke | Invoke the [AndThen] functionopen fun invoke(a: A): B |
map | Alias for andThenfun <C> map(f: (B) -> C): AndThen <A, C> |
toString | open fun toString(): String |
id | fun <A> id(): AndThen <A, A> |
invoke | Wraps a function in AndThen.operator fun <A, B> invoke(f: (A) -> B): AndThen <A, B> |
just | fun <A, B> just(b: B): AndThen <A, B> |
tailRecM | fun <I, A, B> ~~tailRecM~~(a: A, f: (A) -> AndThenOf <I, Either <A, B>>): AndThen <I, B> |
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> |
conest | fun <F, A, B> CounnestedType <F, A, B>.conest(): ConestedType <F, A, B> |
fix | fun <A, B> AndThenOf <A, B>.~~fix~~(): AndThen <A, B> |
invoke | operator fun <A, B> AndThenOf <A, B>.~~invoke~~(a: A): B |
Do you like Arrow?
✖