<@U49C23P5J> forgot also to mention: ``` OptionT.m...
# arrow
r
@jtonic forgot also to mention:
Copy code
OptionT.monad<EitherKindPartial<String>>()  
//is now
OptionT.monad(Either.monad<String>())
👍 1
j
Thank you Raul, I am still struggling with a compilation error.
Copy code
fun getMovies(artistName: String): Either<String, Option<List<String>>> {
            return when (artistName) {
                "Brad Pitt" -> Either.right(Option.just(listOf("Troy", "The inglorious bastards")))
                "Angelina Jolie" -> Either.right(Option.just(listOf("Lara Croft", "Original Sin", "Changeling")))
                "Antonel Ernest Pazargic" -> Either.right(Option.empty())
                else -> Either.left("Error accessing db...")
            }
        }

        val bradPittMovies: Either<String, Option<List<String>>> = getMovies("Brad Pitt")
        val angelinaJolieMovies: Either<String, Option<List<String>>> = getMovies("Angelina Jolie")

        OptionT.monad(Either.monad<List<String>>()).binding {
            val bradPittMovies: List<String> = OptionT(bradPittMovies).bind()
            val angelinaJolieMovies: List<String> = OptionT(angelinaJolieMovies).bind()
        }.value().fix()
Error:(45, 48) Kotlin: Type mismatch: inferred type is OptionT<Kind<ForEither, String>, List<String>> but Kind<OptionTPartialOf<EitherPartialOf<List<String>> /* = Kind<ForEither, List<String>> /> / = Kind<ForOptionT, EitherPartialOf<List<String>> /* = Kind<ForEither, List<String>> */> */, List<String>> was expected Thank you in advance for your further clarifications.
The compilation errors are because of OptionT(bradPittMovies).bind() OptionT(angelinaJolieMovies).bind()
r
Let me take a look
It should be :
OptionT.monad(Either.monad<String>())
instead of
OptionT.monad(Either.monad<List<String>>())
because the Left on your Either is of type String
and in a monadic computation over either the Left is ignored since Either is right biased and flatMap happens just on the Right case.
j
Hi Raul, My mistake, sorry. Thank you for pointing this out. I really need to dive a little bit deeper in the arrow code, in order to get acquainted with the FP patterns/types. Talking about the book (Functional Kotlin) I found it very useful for anyone who needs to go with FP and Kt. Kr.
r
No worries glad to help whenever. I may also give it a shot at your code to provide an alternative implementation
Also Re
Functional Kotlin
I’m sure @dh44t would love to read that you just said ^^^ 🙂