object lib: | |
import scala.annotation.implicitNotFound | |
import scala.util.boundary, boundary.* | |
opaque type Lab[T <: Singleton] >: Unit = Unit | |
object Lab: | |
inline def apply[T <: Singleton]: Lab[T] = () | |
inline def label[T <: Singleton & String]( | |
inline f: Label[Lab[T]] ?=> Unit |
cats-effect Resource
is extremely handy for managing the lifecycle of stateful resources, for example database or queue connections. It gives a main interface of:
trait Resource[F[_], A] {
/** - Acquire resource
* - Run f
* - guarantee that if acquire ran, release will run, even if `use` is cancelled or `f` fails
import scala.languageFeature.higherKinds | |
import cats.{Applicative, Id, ~>} | |
object Shapes { | |
case class Child[F[_]](nickname: F[String], age: F[Int]) | |
case class Adult[F[_]](job: F[String], innerChild: Child[F]) | |
class ApplicativeTrans[F[_]](implicit applicativeF: Applicative[F]) extends ~>[Id, F] { | |
override def apply[A](value: A): F[A] = applicativeF.pure(value) |
// ==UserScript== | |
// @name Mike's timesheet improvements | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description Add plus time buttons to the new GetMyTime | |
// @author Michael Maurizi | |
// @match https://app.getmytime.com/timesheet.aspx | |
// @grant none | |
// ==/UserScript== |
class Nil | |
class Cons[X, Xs] | |
class First[List] { type X } | |
object First { | |
type Aux[List, X0] = First[List] { type X = X0 } | |
implicit val nilFirst: Aux[Nil, Nil] = ??? | |
implicit def consFirst[X0, Xs]: Aux[Cons[X0, Xs], X0] = ??? | |
} |
Tageless Final interpreters are an alternative to the traditional Algebraic Data Type (and generalized ADT) based implementation of the interpreter pattern. This document presents the Tageless Final approach with Scala, and shows how Dotty with it's recently added implicits functions makes the approach even more appealing. All examples are direct translations of their Haskell version presented in the Typed Tagless Final Interpreters: Lecture Notes (section 2).
The interpreter pattern has recently received a lot of attention in the Scala community. A lot of efforts have been invested in trying to address the biggest shortcomings of ADT/GADT based solutions: extensibility. One can first look at cats' Inject
typeclass for an implementation of [Data Type à la Carte](http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesA
// These lines go in ~/.sbt/0.13/global.sbt | |
watchSources ++= ( | |
(baseDirectory.value * "*.sbt").get | |
++ (baseDirectory.value / "project" * "*.scala").get | |
++ (baseDirectory.value / "project" * "*.sbt").get | |
) | |
addCommandAlias("rtu", "; reload ; test:update") | |
addCommandAlias("rtc", "; reload ; test:compile") | |
addCommandAlias("ru", "; reload ; update") |