JorgeCastilloPrz / ArrowAndroidSamples

Functional Programing Android architecture using http://arrow-kt.io/
426 stars 38 forks source link

Concrete AsyncResult monad transformer #3

Closed raulraja closed 7 years ago

raulraja commented 7 years ago

The following PR encapsulates the application concerns in a single datatype representing a Monad transformer that allows monadic computation and encapsulation of the following Application concerns:

typealias Result<A> = Kleisli<EitherTF<Future.F, CharacterError>, GetHeroesContext, A>

An Async Result can handle dependency injection of GetHeroesContext values thanks to Kleisli which is the same as a Reader monad but parametric to other monads in this case Future whereas Reader is parametric to the Id monad.

An AsyncResult is a MonadError<AsyncResult.F, CharacterError> able to handle and raise errors in the context of CharacterError.

The nested EitherT over Future allows us to bind directly to the underlying A value when using flatMap and monadic comprehensions.

This PR also demonstrate the use of monadic comprehensions thanks to kategory a typed FP library for the Kotlin programming language.