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
| trait MonadTrans[T[_[_], _]] { | |
| def lift[M[_]: Monad, A](ma: M[A]): T[M, A] | |
| def hoist[M[_]: Monad, N[_]: Monad, A](tma: T[M, A])(f: M ~> N): T[N, A] | |
| } | |
| object MonadTrans { | |
| def apply[T[_[_], _]: MonadTrans]: MonadTrans[T] = implicitly | |
| } | |
| implicit def applicativeAskMonadTrans[T[_[_], _]: MonadTrans, M[_]: Monad, R] |
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
| trait KVStore[F[_]] { | |
| def get(key: String): F[Option[String]] | |
| def put(key: String, a: String): F[Unit] | |
| } | |
| class TestInterpreter() extends KVStore[IO] { | |
| def get(key: String): IO[Option[String]] = IO { | |
| println("Hit network!") | |
| Option(key + "!") |
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
| @typeclass trait Semigroup[A] { | |
| def combine(x: A, y: A): A | |
| } | |
| @typeclass trait Monoid[A] extends Semigroup[A] { | |
| def id: A | |
| } | |
| @typeclass trait Semigroupal[F[_]] { | |
| def product[A, B](ga: F[A], gb: F[B]): F[(A, B)] |
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
| module Algebra where | |
| import Prelude | |
| import Control.Monad.Eff (Eff) | |
| import Data.Maybe (Maybe(..)) | |
| newtype ConsoleAlg f = ConsoleAlg | |
| { printLn :: String -> f Unit | |
| , readLn :: f 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
| @typeclass trait NonEmptyTraverseUnordered[F[_]] { | |
| def nonEmptyTraverseUnordered[G[_]: CommutativeApply, A, B](sa: F[A])(f: A => G[B]): G[F[B]] | |
| def nonEmptySequenceUnordered[G[_]: CommutativeApply, A](fga: F[G[A]]): G[F[A]] = | |
| nonEmptyTraverseUnordered(fga)(identity) | |
| } | |
| @typeclass trait NonEmptyCommutativeParallel[F[_], M[_]] { | |
| def commutativeApply: CommutativeApply[F] | |
| def commutativeFlatMap: CommutativeFlatMap[M] |
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
| package cats.free | |
| import cats.free.Free.{FlatMapped, Pure, Suspend} | |
| import cats.{Applicative, Monad, Parallel, ~>} | |
| import cats.implicits._ | |
| class FreeParallel[S[_], A](val value: Free[FreeApplicative[S, ?], A]) extends AnyVal | |
| object FreeParallel { | |
| def apply[S[_], A](fp: Free[FreeApplicative[S, ? ], A]): FreeParallel[S, A] = new FreeParallel(fp) |
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._ | |
| import cats.implicits._ | |
| trait Alg[M[_]] { | |
| def doSomething(s: String): M[Unit] | |
| } | |
| object AlgVect extends Alg[Vector] { | |
| def doSomething(s: String): Vector[Unit] = Vector(println(s)) | |
| } |
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
| type Stack[E, A] = EitherT[Future, NonEmptyList[E], A] | |
| def longRunningComputation(person: Person): Future[Either[NonEmptyList[Error], Result]] = ??? | |
| val people: List[Person] = ??? | |
| val result: Stack[Error], List[Result]] = | |
| people.parTraverse(longRunningComputation _ andThen EitherT.apply) |
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
| class IO[+T](run: => T) { | |
| def map[R](f: T => R): IO[R] = { | |
| IO(f(run)) | |
| } | |
| def flatMap[R](f: T => IO[R]): IO[R] = { | |
| IO(f(run).unsafeRun()) | |
| } | |
| def unsafeRun(): T = run |
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
| module Main where | |
| import OutWatch | |
| import Builder ((<==)) | |
| import Control.Monad.Eff (Eff) | |
| import Prelude (Unit, map, (#), (+)) | |
| import RxJS.Observable (interval, startWith) | |
| main :: Eff () Unit | |
| main = let |