This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.{Actor, ActorRef, ActorSystem, Props} | |
object Main extends App { | |
object Console { | |
case class Print(msg: String) | |
case object GetLine | |
case class UserInput(input: String) | |
} | |
class ConsoleActor extends Actor { | |
def receive: Receive = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz.zio.{DefaultRuntime, Fiber, Task, UIO, ZIO} | |
object Main extends App { | |
object ConsoleIO { | |
trait Service { | |
def putStr(msg: String): Task[Unit] | |
def getStr: Task[String] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main extends App { | |
trait Console[F[_]] { | |
def putStr(msg: String): F[Unit] | |
def getStr: F[String] | |
} | |
object Console { | |
def apply[F[_]](implicit F: Console[F]): Console[F] = F | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.free.Free | |
import cats.~> | |
import freek.{:|:, DSL, NilDSL} | |
import freek._ | |
object Main extends App { | |
sealed trait Console[A] | |
case class Print(msg: String) extends Console[Unit] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main extends App { | |
case class Coproduct[F[_], G[_], A](run: Either[F[A], G[A]]) | |
trait Monad[F[_]] { | |
def pure[A](x: A): F[A] | |
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] | |
} | |
object Monad { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main extends App { | |
trait Console { | |
def printLine(msg: String): Unit | |
def readLine: String | |
} | |
trait ConsoleComponent { | |
val console: Console | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.effect.IO | |
import scala.util.{Failure, Success, Try} | |
object Main extends App { | |
/** | |
* Pure functions, we're good! | |
*/ | |
def putStr(msg: String): IO[Unit] = IO(print(msg)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main extends App { | |
print("Please enter a number: ") | |
val number = scala.io.StdIn.readInt() | |
var total = 1 | |
for (x <- 1 to number) | |
total = total * x | |
println("Factorial of " + number.toString + " is " + total.toString) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait UserInteraction[A] | |
// An effect that takes a String and retuns Unit vvvv | |
case class Tell(statement: String) extends UserInteraction[Unit] | |
// An effect that takes a String and retuns a String vvvvvv | |
case class Ask(question: String) extends UserInteraction[String] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Simple sum type with two options | |
data Maybe a = Just a | Nothing | |
-- Safe total function that never throws | |
divide :: Int -> Int -> Maybe Int | |
divide dividend divisor = if divisor == 0 then Nothing else Just (dividend / divisor) | |
-- Maybe is available in Data.Maybe module |