This file contains 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
trait Dep[T] | |
trait Pack[T] { | |
val dep: Dep[T] | |
val t: T | |
} | |
object Pack { | |
def apply[T](d: Dep[T], t0: T) = | |
new Pack[T] { val dep = d ; val t = t0 } |
This file contains 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 shapeless._, record._, syntax.singleton._ | |
import shapeless._ | |
import record._ | |
import syntax.singleton._ | |
scala> val mary = ('name ->> "Mary" :: 'age ->> 23 :: HNil).record | |
mary: shapeless.syntax.DynamicRecordOps[shapeless.::[String with shapeless.record.KeyTag[Symbol with shapeless.tag.Tagged[String("name")],String],shapeless.::[Int with shapeless.record.KeyTag[Symbol with shapeless.tag.Tagged[String("age")],Int],shapeless.HNil]]] = DynamicRecordOps(Mary :: 23 :: HNil) | |
scala> mary.name | |
res2: String = Mary |
This file contains 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
miles@frege:~$ scala | |
Welcome to Scala version 2.11.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_55). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> :power | |
** Power User mode enabled - BEEP WHIR GYVE ** | |
** :phase has been set to 'typer'. ** | |
** scala.tools.nsc._ has been imported ** | |
** global._, definitions._ also imported ** |
This file contains 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) | |
sealed trait Content | |
case class A() extends Content | |
case class B() extends Content | |
// Exiting paste mode, now interpreting. | |
This file contains 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 demo | |
import scalaz._ | |
import scalaz.syntax._ | |
import scalaz.effect.IO | |
import scalaz.effect.IO._ | |
import scalaz.syntax.std.either._ | |
object Demo { | |
type M[A] = EitherT[IO, Throwable, A] |
This file contains 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 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 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 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 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], |