https://kotlinlang.org logo
#functional
Title
# functional
p

pakoito

03/27/2020, 9:28 PM
Copy code
myThing
  .flatTap { element: String -> IO { log(element) } }
  .flatMap { element: String -> continueProgram(element) }
d

dnowak

04/01/2020, 11:44 AM
@pakoito Thank you very much for the advice. It always pays back to read the whole documentation of the library you are using 🙂.
flatTap
is what I was looking for.
😍 1
We use
IO<Either<E, R>>
a lot so we use
EitherT
a lot too. Is there any way to provide
IO<B>
to EitherT’s
flatTap
? The compiler insists on
IO<Either>
, so I ended up with this snippet:
Copy code
.flatTap(IO.monad()) { events ->
                        EitherT(IO
                                .effect { logger.debug { "Leger: <$ledgerId> has events: <$events>" } }
                                .map { Unit.right() })
                    }
p

pakoito

04/01/2020, 12:00 PM
yikes
it looks correct
so in 0.11 we'll have IO<E, A> and you won't need EitherT
0.10.5 is the last release of that series
d

dnowak

04/01/2020, 12:16 PM
I will try to hide it in extension function. I can’t wait to use 0.11 🙂
2 Views