Skip to content

Instantly share code, notes, and snippets.

View jeremyrsmith's full-sized avatar

jeremyrsmith

  • Netflix
View GitHub Profile
@jeremyrsmith
jeremyrsmith / session.scala
Created July 18, 2018 17:07
HKT inference failure with DepFn and Aux
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 November 28, 2016 16:00
Compile-time character HList
import scala.reflect.macros.whitebox
import shapeless._
import scala.language.experimental.macros
trait SingletonChars[S <: String] {
type Out <: HList
}
object SingletonChars {
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 October 18, 2016 03:10
Shapeless typeclass with erasure trick
import shapeless._
trait TestTypeclassRecursive[T] {
def doFoo(t: T): String
}
object TestTypeclassRecursive {
implicit val hnil: TestTypeclassRecursive[HNil] = new TestTypeclassRecursive[HNil] {
/**
* 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
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._