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.{MonadError, StackSafeMonad} | |
| import scala.concurrent.{ExecutionContext, Future} | |
| import scala.util.{Failure, Success, Try} | |
| package object effects { | |
| type F[E, A] = ExecutionContext => Future[Either[E, A]] | |
| object 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
| package effects | |
| import cats.{MonadError, StackSafeMonad} | |
| import scala.concurrent.{ExecutionContext, Future} | |
| import scala.util.{Failure, Success, Try} | |
| final case class F[+E, +A](value: Future[Either[E, A]]) extends AnyVal { | |
| def fold[B](fe: E => B, fa: A => B)(implicit ec: ExecutionContext): Future[B] = value.map { |
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.{Id, Monad, Traverse, ~>} | |
| import scala.concurrent.{Await, Future} | |
| import scala.concurrent.duration.Duration | |
| object TagLess extends App { | |
| case class PurchaseOrderId(value: String) | |
| case class ProductId(value: String) | |
| case class LocationId(value: 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
| import shapeless.{ ::, Generic, HList, HNil, Lazy } | |
| object ShapelessDSL extends App { | |
| trait Amount[A] { | |
| def zero: A | |
| def plus(a: A, b: A): A | |
| def times(a: A, b: BigDecimal): A | |
| } |
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 FinanceDSL extends App { | |
| trait PrettyPrint[A] { | |
| def prettify(a: A): String | |
| class Ops(a: A) { | |
| def pretty: String = prettify(a) | |
| } | |
| } | |
| object PrettyPrint { |
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 FreeMonadExplained { | |
| import scala.language.higherKinds | |
| import scala.language.implicitConversions | |
| sealed trait Interact[A] | |
| case class Ask(prompt: String) extends Interact[String] | |
| case class Tell(message: String) extends Interact[Unit] | |
| // No access to the username captured by the Ask |