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
View coproducttest.scala
import shapeless._
import ops._
import coproduct._
object coproducttest {
type U = Int :+: String :+: CNil
type V = Double :+: List[Int] :+: CNil
View gist:b1c515d5641fe31634bd
package fommil.polys
import shapeless._
sealed trait Trait
case class Foo() extends Trait
case class Bar() extends Trait
trait Thing[T] { def thingy: String }
View TableExample.scala
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 Aug 29, 2015 — forked from xuwei-k/Foldable.scala
Trampolined to avoid stack overflow ...
View Foldable.scala
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] =
View FlattenTupleExample.scala
object FlattenTuple {
import shapeless._
import ops.tuple.FlatMapper
import syntax.std.tuple._
trait LowPriorityFlattenTuple extends Poly1 {
implicit def default[T] = at[T](Tuple1(_))
}
View gist:6510067
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 {
View gist:6357743
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 =
View gist:6345757
/*
- 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
*/
View gist:6344958
/*
- 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
*/
View 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]
You can’t perform that action at this time.