Skip to content

Instantly share code, notes, and snippets.

Avatar

jeremyrsmith

  • Netflix
View GitHub Profile
@jeremyrsmith
jeremyrsmith / session.scala
Created Jul 18, 2018
HKT inference failure with DepFn and Aux
View session.scala
import scala.language.higherKinds
trait Foo[A] {
type Out[_]
def apply[T](t: T): Out[T]
}
object Foo {
type Aux[A, Out0[_]] = Foo[A] { type Out[A] = Out0[A] }
@jeremyrsmith
jeremyrsmith / SingletonChars.scala
Created Nov 28, 2016
Compile-time character HList
View SingletonChars.scala
import scala.reflect.macros.whitebox
import shapeless._
import scala.language.experimental.macros
trait SingletonChars[S <: String] {
type Out <: HList
}
object SingletonChars {
View Option.scala
sealed trait Option[+T]
case object None extends Option[Nothing]
case class Some[@specialized +T](value: T) extends Option[T]
object Option {
implicit class Ops[A](val opt: Option[A]) extends AnyVal {
@inline final def get(): A = opt match {
@jeremyrsmith
jeremyrsmith / typeclass.scala
Last active Oct 18, 2016
Shapeless typeclass with erasure trick
View typeclass.scala
import shapeless._
trait TestTypeclassRecursive[T] {
def doFoo(t: T): String
}
object TestTypeclassRecursive {
implicit val hnil: TestTypeclassRecursive[HNil] = new TestTypeclassRecursive[HNil] {
View pickle-mux.scala
/**
* This demonstrates creating a trivial protocol and service on top of Mux.
* The protocol used is scala.pickling, but it could just as easily use Scodec,
* Avro, or anything else that can SerDe to/from a byte array. All that would
* need replacing is the BinaryPickleFilter and the PickleBinaryFilter.
*
*/
import com.twitter.finagle._
import com.twitter.io.Buf
View spray-json-macro.scala
package com.github.jeremyrsmith.util
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
import _root_.spray.json._
package object spray {
object MacroImpl {
def impl[T: c.WeakTypeTag](c: Context): c.Expr[JsonFormat[T]] = {
import c.universe._, Flag._, definitions._