I want to write that code:
IO.foreverM:
IO.sleep(1.seconds) *> IO.println("Tick")
But it doesn't compile. However this code compiles:
FlatMap[IO].foreverM:
IO.sleep(1.seconds) *> IO.println("Tick")
Can the first one code be complied somehow?
The
IOobject doesn't contain aliases for every single typeclass operation it supports. There's no import that provides anIO.foreverM, though you could certainly write one, and there's been a proposal to add all such methods to theIOobject for this reason.In general most code you see using cats will prefer using typeclass methods on instances instead of via companion objects. Like Luis suggested in the comments,
(IO.sleep(1.seconds) *> IO.println("Tick")).foreverM