Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Bruno Fernandes
    @bfdes

    Hello :wave: ,
    We are looking to add monix-bio support to the weaver test framework, in the same way as we have for Monix: disneystreaming/weaver-test#63

    To that end, I wondered whether there are documented ways to summon Cats Effect instances like Timer, ContextShift, ConcurrentEffectfor monix-bio's Task.

    Piotr Gawryś
    @Avasil

    @bfdes
    Timer and ContextShift should be available for "free" (e.g. https://github.com/monix/monix-bio/blob/master/core/shared/src/main/scala/monix/bio/IO.scala#L5235 ) and ConcurrentEffect if there is implicit Scheduler in scope (IO.catsEffect(s) could work manually) without doing anything. Did you run into any problems?

      implicit def timer: Timer[Task]     = Task.timer(scheduler)
      implicit def cs: ContextShift[Task] = Task.contextShift(scheduler)

    is redundant unless this is a different scheduler than the one you pass when running the task

    Bruno Fernandes
    @bfdes
    @Avasil thanks that worked as
    implicit def timer: Timer[Task]     = IO.timer(scheduler)
    implicit def cs: ContextShift[Task] = IO.contextShift(scheduler)
    Olivier Mélois
    @Baccata

    @Avasil :wave: , in case you don't see the notification : we could use a little bit of guidance there :

    https://github.com/disneystreaming/weaver-test/pull/83/files#r491327459

    Piotr Gawryś
    @Avasil
    I will take a look in a moment:)
    Olivier Mélois
    @Baccata
    weaver-test now has support for monix-bio :)
    Piotr Gawryś
    @Avasil
    Fantastic, I appreciate it! 🎉
    GKhotyan
    @GKhotyan

    Hi! I was trying to make this issue monix/monix-bio#159
    If I understand correctly, I should use method whenA from cats.Monad and write like this:
    def whenA(cond: Boolean)(action: => IO[E, Unit]): IO[E, Unit] =
    MonadIO[E, *].whenA(cond)(action)

    But I have problem with parameter catsMonad. I'm trying to use catsParallelAny.monad here, but facing with type mismatch. Should I find another way to define catsMonad? Or may be I chose wrong way at the beginning?

    Piotr Gawryś
    @Avasil

    Hello @GKhotyan , thank you for the interest in contributing!
    It seems like the signature needs to be final def whenA[E1 >: E](cond: Boolean)(action: => IO[E1, Unit]): IO[E1, Unit] for Applicative[IO[E1, *]].whenA to work.

    On the other hand, I would prefer to reimplement it, the implementation is very simple

    GKhotyan
    @GKhotyan
    Ok, thank you. I’ll try to write implementation of this method
    GKhotyan
    @GKhotyan
    If i’m not mistaken, correct code should be: final def whenA[E1 >: E](cond: Boolean): IO[E1, Unit] = { if (cond) void else unit }
    Piotr Gawryś
    @Avasil

    Ahh, I was wrong with the signature.
    For some reason I put it as an IO method instead of companion object but if we also have a variant on IO then it wouldn't take action at all.
    On companion object it's simply def when[E](cond: Boolean)(action :=> IO[E, Unit]): IO[E, Unit] regardless of Applicative usage.

    BTW, it seems like someone else has already contributed it in the meantime but I have few low hanging fruits in monix/monix if you'd like to look after something else.

    If you'd like to contribute to monix-bio in particular, there are some methods that would be nice to have in the API, like ZIO's absorb:

    final def absorb(implicit ev: E <:< Throwable): Task[A]
    
    final def absorbWith(f: E => Throwable): Task[A]

    that is equivalent of redeemCauseWith(c => IO.raiseError(c.toThrowable), x => IO.now(x))

    Not sure about the name, if there are no better ideas, we can just settle on absorb.

    There are some other methods that I wanted to include in both Monix and Monix BIO, I will create issues for them tomorrow. Feel free to ping me if I don't do that :sweat_smile:

    GKhotyan
    @GKhotyan
    Ok, I’ll try to handle this and be first this time :)
    Piotr Gawryś
    @Avasil
    In general, it's best to post on the issue that you're working on it to prevent such situations :D
    Piotr Gawryś
    @Avasil
    @GKhotyan I've created few more issues! I also have some less trivial ideas in my head if you're interested.
    GKhotyan
    @GKhotyan
    Thank you! I’ll be glad to take something more difficult after low hanging fruit :)
    GKhotyan
    @GKhotyan
    Trying to make IO.flatTap. That’s what I have:
    /** Creates a new Task by applying a monadic function to the successful result
    • of the source Task, and discard the result.
      */
      final def flatTap[E1 >: E, B](f: A => IO[E1, B]): IO[E1, A] = { this.flatMap { a => f(a).map(_ => a) } }
      but comparing to cats flatTap where F could be List or Option, here F is always IO, so I’m confused. May be this code is not what required?
    Piotr Gawryś
    @Avasil
    @GKhotyan The code looks fine :)
    GKhotyan
    @GKhotyan
    Ok, great)
    GKhotyan
    @GKhotyan
    @Avasil Hi! I made pull request with methods absorb and absorbWith which you write few days ago monix/monix-bio#180. Hope, it make sense :)
    Piotr Gawryś
    @Avasil
    Thank you, I'll take a look tonight!
    WesselVS
    @WesselVS
    Hi there, thanks for this great library! Are there plans to integrate the just merged improved tracing from monix? Also, if I were to take a shot at this myself, what would be a good approach? Is bio forked from monix, so that I can pull in the master branch from monix into bio?
    Piotr Gawryś
    @Avasil

    Hello @WesselVS

    Are there plans to integrate the just merged improved tracing from monix?

    Yes, I've planned to do this after releasing stack traces for Monix that I want to do within a few days

    Also, if I were to take a shot at this myself, what would be a good approach?

    It would require copying relevant changes from this PR: https://github.com/monix/monix/pull/1267/files
    monix-bio depends on monix-execution so RingBuffer will be available but the rest needs to be duplicated.

    The structure is very similar so integration should be a straightforward but manual task.

    Is bio forked from monix, so that I can pull in the master branch from monix into bio?

    It's not a fork but it depends on some modules

    If you'd like to help out then that would be fantastic

    WesselVS
    @WesselVS
    Thanks! Ok, so I’m pretty far, all of the unit tests of bio succeed, but the tracing tests that I ported from monix fail with a off-by-one error, monix produces one additional trace. I’m going to look into this. Really fun to see the internals of the library.
    Piotr Gawryś
    @Avasil

    but the tracing tests that I ported from monix fail with a off-by-one error, monix produces one additional trace.

    That's acceptable, the best way to check is to print the stack trace, compare to monix.eval.Task and decide if both make sense

    Awesome, it will speed up monix-bio release a lot :)
    WesselVS
    @WesselVS

    Thanks! Just out of curiosity: I'm seeing this in the monix trace (in the test captures bracket frames of FullStackTracingSuite):

    TaskTrace: 13 frames captured
     ├ apply @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:117)
     ├ apply @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:117)
     ├ runToFuture @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:130)
     ├ <clinit> @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:117)
     ├ runToFuture @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:130)
     ├ pure @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:117)
     ├ runToFuture @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:130)
     ├ <clinit> @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:117)
     ├ bracket @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:117)
     ├ flatMap @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:117)
     ├ flatMap @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:117)
     ├ flatMap @ tracing.FullStackTracingSuite$.traced (FullStackTracingSuite.scala:12)
     ╰ map @ tracing.FullStackTracingSuite$.new (FullStackTracingSuite.scala:120)

    Why is runToFuture there 3 times? The trace I'm getting in monix-bio lists the runToFuture only 2 times, but I'm trying to figure out why it's there more than once.

    WesselVS
    @WesselVS
    WesselVS
    @WesselVS
    and a silly small one, since I miss *> <* pretty bad from monix: monix/monix-bio#191
    Piotr Gawryś
    @Avasil
    Thank you, I will take a look as soon as I deal with main monix release :)
    Piotr Gawryś
    @Avasil
    Regarding repeated runToFuture - I haven't figured it out yet, don't worry about it. Hopefully, we will clean up it in the future but that's fine for now
    WesselVS
    @WesselVS
    Ok, thanks! Eagerly waiting for this to be released :)
    Piotr Gawryś
    @Avasil
    Sadly, I didn't manage to finish the release last weekend but there's a good chance I will pull the trigger tomorrow and review your bio PR during the weekend :) Shouldn't take long to release the new monix-bio version
    WesselVS
    @WesselVS
    Awesome!
    WesselVS
    @WesselVS
    Hi Piotr, when do you have time to look at the traces PR?
    Piotr Gawryś
    @Avasil
    Hi, I have it on my today's todo list! I will probably merge it and then aim to have a release around the weekend after I port some other changes and make some adjustments if needed
    WesselVS
    @WesselVS
    Alright, cool! Thanks
    Piotr Gawryś
    @Avasil
    Released 1.1.0 with stack traces :) https://github.com/monix/monix-bio/releases/tag/v1.1.0
    cc @WesselVS
    WesselVS
    @WesselVS
    Very nice! Thank you
    Eliav Lavi
    @eliavlavi
    Hello! I am wondering if there's any example showing interop with Future - while using a custom error type and not working with Throwable. Any tip?
    Eliav Lavi
    @eliavlavi
    More specifically... I am working with the Scanamo lib, which returns a Future[Either[SomeFailure, A]] for many of its operations. I would like transform that into an IO[SomeFailure, A] and work with it until I have to actually serve the data (then runToFuture). I assume whatever used to be a failed Future in the past is a fatal\terminal error in the context of IO... am I getting it right? Is this a supported use case?
    Piotr Gawryś
    @Avasil

    Hello @eliavlavi

    Your understanding is correct. It's similar with fromTryEither

    It's equivalent of IO.deferFuture(f).hideErrors.rethrow.
    Unfortunately, there's no built-in operator for that but I think we really need it if you're interested in contributing.
    I see that I even implemented TaskFromFutureEither in low-level code but I don't remember why I didn't expose it in the API :sweat_smile:

    Eliav Lavi
    @eliavlavi
    Thanks @Avasil, that helped!
    Do you mean you'd like to have a def fromFutureEither[E, A](a: => Future[Either[E, A]]): IO[E, A]?
    Piotr Gawryś
    @Avasil
    Yes
    Eliav Lavi
    @eliav-lavi
    Cool. I'll try work on that.
    (Seems fit in IO.scala right under def fromFuture to me, but I am not sure where should the test go - TaskFromFutureSuite.scala? new file?)
    Piotr Gawryś
    @Avasil
    Thank you, I've left some comments on PR, new file is perfectly fine
    Eliav Lavi
    @eliav-lavi
    Thanks, fixed and added 🙃
    WesselVS
    @WesselVS
    At work, we use Monix’s observable a lot, that uses monix.eval.Task. We defined an implicit conversion between bio and eval tasks. What’s the proper way of doing this?
    Piotr Gawryś
    @Avasil

    @WesselVS You can do a conversion like this: https://bio.monix.io/docs/cats-effect#monixevaltask

    I have some plans to make Observable easier to use with IO[E, A] (without conversions) but it is not a top priority for me right now