Class/Object

com.olegpy.meow.effects

Consumer

Related Docs: object Consumer | package effects

Permalink

final class Consumer[F[_], A] extends AnyVal

A wrapper for effectful function A => F[Unit]

Linear Supertypes
AnyVal, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Consumer
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. val consume: (A) ⇒ F[Unit]

    Permalink
  6. def getClass(): Class[_ <: AnyVal]

    Permalink
    Definition Classes
    AnyVal → Any
  7. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  8. def runTell[B](f: (FunctorTell[F, A]) ⇒ B)(implicit F: Functor[F]): B

    Permalink

    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 ()
  9. def tellInstance(implicit F: Functor[F]): FunctorTell[F, A]

    Permalink

    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

    See also

    runTell for potentially more convenient usage

  10. def toString(): String

    Permalink
    Definition Classes
    Any

Inherited from AnyVal

Inherited from Any

Ungrouped