kierans777
06/17/2021, 4:18 AMEither
. For example (Int) -> Either<Error, Int>
. I can use monandic comprehensions ie:
val c = either {
val a = func1(1).bind()
val b = func2(a).bind()
b
}
However I want to create a pipe/composition to remove the intermediate variables. In pseudo code
val pipe = func2 composeK func1
val c = pipe(1)
Is this possible?Patrick Louis
06/17/2021, 4:59 AMinfix fun <A,E,B,C> ((A)->Either<E,B>).composeK(ff: (B)->Either<E,C>): (A)->Either<E,C> =
{ a: A -> this(a).flatMap(ff)}
As the Typeclasses have been dropped with 0.13, you can unfortunately no longer write one for Monads in generalPatrick Louis
06/17/2021, 5:01 AMkierans777
06/17/2021, 6:32 AMkierans777
06/17/2021, 6:34 AMAs the Typeclasses have been dropped with 0.13, you can unfortunately no longer write one for Monads in generalAs a newbie to Arrow, can you help me understand why Typeclasses were dropped? Or that the ability to compose functions returning monads together isn't in Arrow? For context, I've done FP in Crocks (Javascript) and Clojure so having to figure out how to map what I want to do to Kotlin/Arrow.
kierans777
06/17/2021, 7:02 AMflatMap
a suspended function?Patrick Louis
06/17/2021, 7:22 AMsuspend infix fun <A, E, B, C> (suspend (A) -> Either<E, B>).composeK(ff: suspend (B) -> Either<E, C>): suspend (A) -> Either<E, C> =
{ a: A -> either { ff(this@composeK(a).bind()).bind() } }
granted, it doesn't look as elegant as the previous version, but it works in a similar fashion.kierans777
06/17/2021, 7:26 AMthis
.kierans777
06/17/2021, 7:27 AMPatrick Louis
06/17/2021, 7:29 AMcomposeK
function, so the (suspend (A) -> Either<E, B>)
partPatrick Louis
06/17/2021, 7:31 AMkierans777
06/17/2021, 7:40 AMstojan
06/18/2021, 8:07 AMstojan
06/18/2021, 10:04 AM