Skip to content

Instantly share code, notes, and snippets.

@btlines
btlines / F.scala
Created Sep 6, 2020
A better Future
View F.scala
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 {
View TagLessExample.scala
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)
@btlines
btlines / ShapelessDSL.scala
Created Mar 3, 2017
FinanceDSL with automatic class type derivation using Shapeless
View ShapelessDSL.scala
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
}
@btlines
btlines / FinanceDSL.scala
Last active Mar 22, 2018
FinanceDSL using type-classes
View FinanceDSL.scala
object FinanceDSL extends App {
trait PrettyPrint[A] {
def prettify(a: A): String
class Ops(a: A) {
def pretty: String = prettify(a)
}
}
object PrettyPrint {
View FreeMonadExplained.scala
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
You can’t perform that action at this time.