cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Add timed variant for IO[Unit]

Open geirolz opened this issue 1 year ago • 1 comments

Hello folks! I'm not sure about the solution but I encountered this "problem" enough times to submit this PR. Basically when you want to use timed on an IO[Unit] you have to map the result to just keep the left side of the tuple. It would be nice to have a method to this directly within IO.

My proposal here introduces breaking changes, other more conservative solutions would be to use a dedicated name for this case such as:

  • timed_
  • timedIgnore (with or without and )
  • timedL or timedR it depends on which side you see it
  • timedOnly

Let me know what do you think! Thank :)

geirolz avatar Jun 26 '24 12:06 geirolz

There's functor syntax in cats.syntax.all that lets you write myUnitIO.timed._1F to achieve the same, would that work for you? I'm no maintainer and this is no direct opinion on the PR, just wondered whether you are aware as it's syntactically very close to what you suggest.

Scastie example: https://scastie.scala-lang.org/5LQicwTuSf2e2Fkrds2qvw

ybasket avatar Jul 15 '24 15:07 ybasket