Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View milessabin's full-sized avatar

Miles Sabin milessabin

View GitHub Profile
import shapeless._
import shapeless.poly._
import shapeless.ops.hlist._
import scala.util.Try
trait Deserializer[A, B] {
def apply(t: A): Either[String, B]
}
object Deserializer {
import org.json4s._
import org.json4s.native.JsonMethods._
import shapeless._
import poly._
import ops.hlist._
import syntax.singleton._
import record._
object JSON {
def compact[A](a: A)(implicit st: toJSON.Case[A] { type Result <: JValue }): String =
/*
- type mismatch; found : com.tagged.vor.toJSON.type required: ?{def apply(x$1: ? >:
A): ?} Note that implicit conversions are not applicable because they are ambiguous:
both method inst1 in trait PolyInst of type [A](fn: shapeless.Poly)(implicit cse:
fn.ProductCase[shapeless.::[A,shapeless.HNil]])A => cse.Result and macro method apply
in object Poly of type (f: Any)shapeless.Poly are possible conversion functions from
com.tagged.vor.toJSON.type to ?{def apply(x$1: ? >: A): ?}
- Unable to convert expression Expr[Nothing](toJSON) to a polymorphic function
value
*/
/*
- type mismatch; found : com.tagged.vor.toJSON.type required: ?{def apply(x$1: ? >:
A): ?} Note that implicit conversions are not applicable because they are ambiguous:
both method inst1 in trait PolyInst of type [A](fn: shapeless.Poly)(implicit cse:
fn.ProductCase[shapeless.::[A,shapeless.HNil]])A => cse.Result and macro method apply
in object Poly of type (f: Any)shapeless.Poly are possible conversion functions from
com.tagged.vor.toJSON.type to ?{def apply(x$1: ? >: A): ?}
- Unable to convert expression Expr[Nothing](toJSON) to a polymorphic function
value
*/
@milessabin
milessabin / Fogus.scala
Last active December 14, 2015 17:39 — forked from puffnfresh/Fogus.scala
import shapeless._
// fogus wanted this:
// [a] -> [b] -> [a b a b ...]
// Follow up question: "Do you know a dependent language with my interleave?"
// Yes. Scala and shapeless even make it a single line!
trait AB[-L <: HList, A, B]
case class ServiceId[T](id : Int)
implicit val lisServiceId =
ServiceId[android.view.LayoutInflater](Context.LAYOUT_INFLATER_SERVICE)
def service[T](implicit sid: ServiceId[T]): T = {
context.getSystemService(sid.id).asInstanceOf[T]
}
import shapeless._
import ops._
import coproduct._
object coproducttest {
type U = Int :+: String :+: CNil
type V = Double :+: List[Int] :+: CNil
package fommil.polys
import shapeless._
sealed trait Trait
case class Foo() extends Trait
case class Bar() extends Trait
trait Thing[T] { def thingy: String }
package shapeless.examples
import shapeless._
import nat._
import ops.hlist._
import test._
object TableExample extends App {
final case class Row[L <: HList](cells: L)
@milessabin
milessabin / Foldable.scala
Last active August 29, 2015 14:17 — forked from xuwei-k/Foldable.scala
Trampolined to avoid stack overflow ...
import scala.util.control.TailCalls._
import shapeless._
trait Foldable[F[_]] {
def foldLeft[A, B](fa: F[A], b: B)(f: (B, A) => B): B
}
object Foldable {
implicit def apply[F[_]](implicit fr: Lazy[FoldableRec[F]]): Foldable[F] =