This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
import shapeless._ | |
trait Query[O] ; trait Query0[O] extends Query[O] ; trait Query1[I1, O] extends Query[O] | |
trait ActorRef[O] | |
trait Rel[-K, V] | |
object Rel { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless._ | |
import ops.function._ | |
// Contravariant version of shapeless's FnToProduct | |
trait ContraFnToProduct[-F] { | |
type Out | |
def apply(f: F): Out | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
import shapeless._, ops.hlist._, ops.record._ | |
object selectAll extends SingletonProductArgs { | |
class Apply[K <: HList] { | |
def from[T, R <: HList, S <: HList, Out](t: T) | |
(implicit | |
gen: LabelledGeneric.Aux[T, R], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package shapeless.examples | |
import shapeless._ | |
import nat._ | |
import ops.hlist._ | |
import test._ | |
object TableExample extends App { | |
final case class Row[L <: HList](cells: L) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used in shapeless here: https://github.com/milessabin/shapeless/blob/master/core/src/main/scala/shapeless/syntax/singletons.scala#L42 | |
scala> def narrow[T <: AnyRef](t: T): t.type = t | |
narrow: [T <: AnyRef](t: T)t.type | |
scala> val s1 = narrow("foo") // Widened | |
s1: String = foo | |
scala> def narrow[T <: AnyRef](t: T): t.type {} = t // Note empty refinement | |
narrow: [T <: AnyRef](t: T)t.type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Demo { | |
// A couple of type classes with type members ... | |
trait Foo[T] { | |
type A | |
} | |
object Foo { | |
implicit val fooIS = new Foo[Int] { type A = String } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import ops.nat._ | |
import ops.nat._ | |
scala> def foo[T, N <: Nat](l: Sized[Seq[T], N])(implicit ev: LTEq[N, _3]) = l | |
foo: [T, N <: shapeless.Nat](l: shapeless.Sized[Seq[T],N])(implicit ev: shapeless.ops.nat.LTEq[N,shapeless.nat._3])shapeless.Sized[Seq[T],N] | |
scala> val l1 = Sized(1, 2, 3) | |
l1: shapeless.Sized[scala.collection.immutable.IndexedSeq[Int],shapeless.nat._3] = shapeless.Sized@17191095 | |
scala> val l2 = Sized(1, 2, 3, 4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object FlattenTuple { | |
import shapeless._ | |
import ops.tuple.FlatMapper | |
import syntax.std.tuple._ | |
trait LowPriorityFlattenTuple extends Poly1 { | |
implicit def default[T] = at[T](Tuple1(_)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.language.experimental.macros | |
import scala.reflect.macros.whitebox | |
trait Foo[T] | |
object Foo { | |
implicit def mkFoo[T]: Foo[T] = macro FooMacros.mkFooImpl[T] | |
} |