Execute an operation that can "log" values of type A
using this Consumer
Execute an operation that can "log" values of type A
using this Consumer
N.B.: unlike most FunctorTell instances, this one does not require
any constraints on A
As an example, a simple async logger that only blocks if a previous message is still being processed, to ensure correct ordering:
def greeter(name: String)(implicit ev: FunctorTell[IO, String]): IO[Unit] = ev.tell(s"Long time no see, $name") >> IO.sleep(1.second) def forever[A](ioa: IO[A]): IO[Nothing] = ioa >> forever(ioa) for { mVar <- MVar.empty[IO, String] logger = forever(mVar.take.flatMap(s => IO(println(s))) _ <- logger.start // Do logging in background _ <- Consumer(mVar.put).runTell { implicit tell => forever(greeter("Oleg")) } } yield ()
Directly return an instance for FunctorTell
that is based on this Consumer
Directly return an instance for FunctorTell
that is based on this Consumer
Returned instance would call the Consumer
function as its tell
operation
runTell for potentially more convenient usage
A wrapper for effectful function
A => F[Unit]