Skip to content

Instantly share code, notes, and snippets.

Miles Sabin milessabin

Block or report user

Report or block milessabin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
non /
Last active Feb 2, 2019
I feel like conversations around laws and lawfulness in Scala are often not productive, due to a lack of rigor involved. I wanted to try to be as clear and specific as possible about my views of lawful (and unlawful) behavior, and what I consider a correct and rigorous way to think about laws (and their limits) in Scala.


A law is a group of two or more expressions which are required to be the same. The expressions will usually involve one or more typed holes ("inputs") which vary.

Some examples:                 === x
almost /
Last active Sep 12, 2019
Reactive 2016 Lightning Talk Proposal: Get Flow

This is a proposal for a lightning talk at the Reactive 2016 conference.

NOTE: If you like this, star ⭐️ the Gist - the amount of stars decides whether it makes the cut! You could also Retweet if you want :)

Get Flow

Type checking JavaScript with Flow

JavaScript is a dynamic language, and there's nothing wrong with that. It allows quick iteration and lowers barriers. However, sometimes some compile-time type checking is just what you need to keep your code in line and give yourself the confidence to build bigger and faster. Flow gives the best of both worlds. You can have normal JavaScript but you can also add types where they're helpful, and it adds zero cost at runtime. In this talk I'll show Flow as it applies to a Redux & React codebase.

raulraja /
Created Feb 10, 2016
Shapeless autolifting Kleisli#local to avoid lambda boilerplate
import cats._
import shapeless._
import shapeless.ops.hlist.Selector
implicit class ReaderOps[A, B, L <: HList](f: Reader[A, B]) {
def liftD[AA](implicit ga: Generic.Aux[AA, L], sel: Selector[L, A]): Reader[AA, B] =
f.local[AA](aa => sel.apply(
bishboria /
Last active Nov 14, 2019
Springer made a bunch of books available for free, these were the direct links
View HasId.scala
import shapeless._
import shapeless.labelled._
import shapeless.ops.record._
import scala.annotation.implicitNotFound
@implicitNotFound("Cannot prove that ${A} has an 'id: Int' field.")
trait HasId[A] {
def apply(a: A): Int
View programatic-use-of-scalac.log
scala> import, reporters._; val reporter = new StoreReporter; val settings = new Settings(); settings.processArgumentString("-usejavacp -Ystop-after:refchecks"); val global = new Global(settings, reporter)
import reporters._
reporter: =
settings: =
Settings {
-d = .
-Ystop-after = List(refchecks)
-usejavacp = true
-encoding = UTF-8
xuwei-k / Foldable.scala
Created Mar 14, 2015
deriving Foldable in Scala
View Foldable.scala
import shapeless._
trait Foldable[F[_]] {
def foldLeft[A, B](fa: F[A], b: B)(f: (B, A) => B): B
object Foldable extends Foldable0 {
def apply[F[_]](implicit F: Lazy[Foldable[F]]): Foldable[F] = F.value
implicit val idFoldable: Foldable[Id] =
View test.scala
trait Test {
type Mapped[F[_]]
type sx[T] = T => String
trait fx[X] {
type λ[T] = T => X
def summon[F[_]]: Mapped[F]
// okay. Inference can unify the higher kinded type variable ?F with sx
summon : Mapped[sx]
View MapReduceTypeClasses.scala
package mapreduce
* This is an attempt to find a minimal set of type classes that describe the map-reduce programming model
* (the underlying model of Google map/reduce, Hadoop, Spark and others)
* The idea is to have:
* 1) lawful types that fully constrain correctness
* 2) a minimal set of laws (i.e. we can't remove any laws,
* 3) able to fully express existing map/reduce in terms of these types
Arneball / gist:a222b99a7b689bde9585
Last active Aug 29, 2015
Macro annotation extension method
View gist:a222b99a7b689bde9585
class ext extends StaticAnnotation {
def macroTransform(annottees: Any*) = macro extension.impl
object extension {
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._{ _.tree }.head match {
case q"def $name[..$tp](...$params): $ret = $b" =>
val Seq(Seq(thiz, rest @ _*), rest2 @ _*) = params
You can’t perform that action at this time.