## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
Gabriele Petronella
@gabro

hi there! Little cats puzzle I'm struggling with:

I have a

List[(A, Future[B], Future[C])]

and I would like to transform it into

Future[List[(A, B, C)]]

I suspect some variant of Traverse will do the trick, but I can't seem to put it together correctly

Martijn Hoekstra
@martijnhoekstra
it feels it should be l.traverse{ case (a, fb, fc) => for { b <- fb; c <- fc} yield (a, b, c)} I think - but there probably are no instances for Future? I don't know for sure. Stdlib has the tools though
from stdlib Future.traverse(l){ case (a, fb, fc) => for { b <- fb; c <- fc} yield (a, b, c)}
Luka Jacobowitz
@LukaJCB
I suspect it should be as simple as
list.traverse{ case (a, fb, fc) =>
(a.pure[Future], fb, fc).tupled
}
Gabriele Petronella
@gabro
ah, good point, I'm probably overlooking a simple solution like that
I was trying to put together a Bitraversable instance
Fabio Labella
@SystemFw
object Q {
import cats._, implicits._
import cats.effect._

type A
type B
type C
def l: List[(A, IO[B], IO[C])] = ???
def r: IO[List[(A, B, C)]] =
l.traverse { t => t.copy(_1 = t._1.pure[IO]).tupled }
}
this compiles
Luka Jacobowitz
@LukaJCB
I like that you smuggled IO in there ðŸ˜œ
Gabriele Petronella
@gabro
thanks, so the gotcha seems to be lifting the first member into the target applicative
Fabio Labella
@SystemFw
@LukaJCB it's a scalafix ;)
Gabriele Petronella
@gabro
and then use traverse
thanks for the super quick help, everyone :)
Luka Jacobowitz
@LukaJCB
Gabriele Petronella
@gabro
once your hammer is a fp library, everything starts to look like a typeclass I guess
Martijn Hoekstra
@martijnhoekstra
once your hammer is a fp library, it turns out that you need to screw Future?
Gabriele Petronella
@gabro
haha, that too
Martijn Hoekstra
@martijnhoekstra
(I regret nothing)
Gabriele Petronella
@gabro
it's a project I'm gradually migrating towards a better world
I inherited it
We'll get to IO/Task :D
Martijn Hoekstra
@martijnhoekstra
They work better with hammers

@SystemFw unfortunately, I'm not getting there with

then you create an instance for that that contains the interpreter code you have now

Martijn Hoekstra
@martijnhoekstra
what shape would that have?
Martijn Hoekstra
@martijnhoekstra
where do I maintain the data state and instruction state?
Fabio Labella
@SystemFw
in the interpreter ?
this is kind of strange language, in that you don't need monads
for this reason, the initial approach (concrete datatype) it's going to be a bit easier
basically define the instructions of Brainfuck as an ADT
your program can be a List[ADT]
I'll be giving it a stab in both styles so I can be more helpful
Martijn Hoekstra
@martijnhoekstra
thank you for going above and beyond
felher
@felher
Is there syntactic sugar for MonadError[F, E].fromEither? Something like myEitherValue.liftError[IO] with myEitherValue : Either[Throwable, String]? I'm currently using MonadError[IO, Throwable].fromEither(myEitherValue) which is not bad, don't get me wrong, but forces me to specify the Throwable again.
Fabio Labella
@SystemFw
you can try yourEither.pure[IO].rethrow
I'm assuming that Either is not produced by running side effects, of course
otherwise it should IO(functionThatReturnsYourEither).rethrow
Alexander Samsig
@Asamsig
If I used sequenceU prior to 1.0.1, should I just enable partial unification and change to sequence?
Luka Jacobowitz
@LukaJCB
Yep :+1:
felher
@felher
@SystemFw yeah, great idea, thanks.
Alexander Samsig
@Asamsig
@LukaJCB The behaivior doesn't seem exactly the same, at least I was having trouble getting it to compile. Since the method type definition was contraining to Either[Failure, Seq[Something]], but when I changed it to Either[Failure, List[Something]]it worked. Does this have any effect?
Luka Jacobowitz
@LukaJCB
AFAIK Seq never had any instances, so it shouldâ€™ve always been List or Vector (:
Alexander Samsig
@Asamsig
I see, so the previous Unapplyimplementation simply accepted it to be upcasted to a Seq?
Luka Jacobowitz
@LukaJCB
I think that may have been whatâ€™s happening yes (:
Alexander Samsig
@Asamsig
Okay great, thank you.
Luka Jacobowitz
@LukaJCB
Paulius Imbrasas
@CremboC
Hey guys, are there any built in monad transformers for Option <-> IO? Perhaps anyone has an example?
Andi Miller
@andimiller
what would you expect those to do?
Luka Jacobowitz
@LukaJCB
Whatâ€™s wrong with OptionT[IO, A]?