Skip to content

Instantly share code, notes, and snippets.

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 = {
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]
}
}
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
}
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]
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 {
object Main extends App {
trait Console {
def printLine(msg: String): Unit
def readLine: String
}
trait ConsoleComponent {
val console: Console
}
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))
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)
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]
-- 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