Skip to content

Instantly share code, notes, and snippets.

View PavelZaytsev's full-sized avatar
🐢

Pavel Zaytsev PavelZaytsev

🐢
View GitHub Profile
case class Reader[E, A](run: E => A)
object Reader {
def >==>[E, A, B, C](fa: A => Reader[E, B],
fb: B => Reader[E, C]): A => Reader[E, C] = { input: A =>
val readerB: Reader[E, B] = fa(input)
flatMap(readerB)(fb)
}
def run[E, A]: Reader[E, A] => E => A = {
case class Writer[W, A](run: (W, A))
trait Monoid[A] {
def combine(a: A, b: A): A
def empty: A
}
object Writer {
def >==>[W: Monoid[W], A, B, C](a: A => Writer[W, B],
sealed trait Option[+A]
case class Some[+A](get: A) extends Option[A]
case object None extends Option[Nothing]
sealed trait EitherError[Exception, +A]
case class RecoverableError(e: Exception)
extends EitherError[Exception, Nothing]
case class Result[+A](value: A) extends EitherError[Exception, A]
object Option {
import scala.concurrent.ExecutionContext
case class Async[A, E](cb: (A => E) => E)
object Async {
def run[A, E](async: Async[A, E])(
implicit ec: ExecutionContext): (A => E) => E = {
case Async(callback) =>
f =>
trait IO[A] {
def run: A // case class parameters may not be call-by-name
// so we put unit in a singleton
}
object IO {
def pure[A](input: => A): IO[A] = new IO[A] { def run: A = input }
def >==>[A, B, C](a: A => IO[B], b: B => IO[C]): A => IO[C] = { input =>
val pureIntput: IO[A] = pure(input)
sealed trait Undecidable[Nothing, +A]
case object Forever extends Undecidable[Nothing, Nothing]
case class Halt[+A](value: A) extends Undecidable[Nothing, A]
object Undecidable {
def >==>[A, B, C](
a: A => Undecidable[Nothing, B],
b: B => Undecidable[Nothing, C]): A => Undecidable[Nothing, C] = {
input: A =>
def f1[A, B]: A => B
def f2[B, C]: B => C
def f3[C, D]: C => D
f1 compose(f2 compose f3) === (f1 compose f2) compose f3 === f1 compose f2 compose f3
def f[A, B]: A => B
def aIdentity[A]: A => A
def bIdentity[B]: B => B
aIdentity compose f === f compose bIdentity
import scalaz.zio.{App, IO, KleisliIO}
case class AppConfig(service1QueueSize: Int,
service1SecretPath: String,
service2SecretPath: String,
service1DBToUse: String,
service2DBToUse: String,
service2MonitoringEndpoint: String)
case class SecretDependencyService(secretPath: String)
case class Reader[E, A](run: E => A)
object Reader {
def run[E, A]: Reader[E, A] => E => A = {
case Reader(runnable) =>
e =>
runnable(e)
}
}