Skip to main content

ConsoleEffect

ConsoleEffect#

import scalaz._import Scalaz._
import effectie.scalaz._import effectie.YesNo
trait Something[F[_]] {  def foo[A](): F[Unit]}
object Something {
  def apply[F[_]: Something]: Something[F] =    implicitly[Something[F]]
  implicit def something[F[_]: ConsoleEffect: Monad]: Something[F] =    new SomethingF[F]
  final class SomethingF[F[_]: ConsoleEffect: Monad]    extends Something[F] {        def foo[A](): F[Unit] = for {      _ <- ConsoleEffect[F].putStrLn("Hello")      answer <- ConsoleEffect[F].readYesNo("Would you like to proceed?")      result = answer match {            case YesNo.Yes =>              "Done"            case YesNo.No =>              "Cancelled"          }      _ <- ConsoleEffect[F].putStrLn(result)    } yield ()  }}
import scalaz.effect._
val foo = Something[IO].foo()foo.unsafePerformIO()
HelloWould you like to proceed?nCancelled
HelloWould you like to proceed?yDone

ConsoleEffectful#

import scalaz._import Scalaz._
import effectie.scalaz.ConsoleEffectful._import effectie.scalaz._import effectie.YesNo
trait Something[F[_]] {  def foo[A](): F[Unit]}
object Something {
  def apply[F[_]: Something]: Something[F] =    implicitly[Something[F]]
  implicit def something[F[_]: ConsoleEffect: Monad]: Something[F] =    new SomethingF[F]
  final class SomethingF[F[_]: ConsoleEffect: Monad]    extends Something[F] {
    def foo[A](): F[Unit] = for {      _ <- putStrLn("Hello")      answer <- readYesNo("Would you like to proceed?")      result = answer match {            case YesNo.Yes =>              "Done"            case YesNo.No =>              "Cancelled"          }      _ <- putStrLn(result)    } yield ()  }}
import scalaz.effect._
val foo = Something[IO].foo()foo.unsafePerformIO()
HelloWould you like to proceed?nCancelled
HelloWould you like to proceed?yDone