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 com.twitter.conversions.time._ | |
import com.twitter.finagle.client._ | |
import com.twitter.finagle.dispatch.SerialClientDispatcher | |
import com.twitter.finagle.util.DefaultTimer | |
import com.twitter.util.{Await, Future} | |
trait ExampleClient { | |
def client: Service[String, String] | |
def sa = new java.net.InetSocketAddress("localhost", 8080) |
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 Obs[+A] { def value: A } | |
object Obs { | |
import shapeless._, poly._, ops.hlist.Mapper, ops.function.FnToProduct | |
object values extends (Obs ~> Id) { | |
def apply[T](t: Obs[T]) = t.value | |
} | |
def calculate[T, V <: HList, L <: HList, F, Z](obss: T)(f: F)(implicit |
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
scalaVersion := "2.11.2" | |
libraryDependencies += "com.chuusai" %% "shapeless" % "2.0.0" | |
name := "Observe Sample" |
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 Conv1[A, B] { def apply(a: A): B } | |
trait Conv2[A, B] { def apply(a: A): B } | |
trait Conv3[-A, B] { def apply(a: A): B } | |
trait Conv4[-A, +B] { def apply(a: A): B } | |
object Conv2 { | |
implicit def fromConv1[A, B](implicit c1: Conv1[A, B]): Conv2[A, B] = | |
new Conv2[A, B] { def apply(a: A) = c1(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
import language.experimental.macros, reflect.macros.Context | |
def demoImpl[X](c: Context)(implicit t: c.WeakTypeTag[X]): c.Expr[X] = { | |
import c.universe._ | |
val companion = t.tpe.typeSymbol.companionSymbol | |
val goodTree = q"$companion(1)" | |
val badTree = q"Foo(1)" |
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.stuff | |
import shapeless._ | |
import nat._ | |
import ops.nat._ | |
import ops.hlist._ | |
/** | |
* The goal is to determine whether a list of numbers is the appropriate length | |
* (nine) and has a valid checksum, which is calculated by taking the sum of |
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
// in bijection branch jco/macro_case_class_plus | |
// ./sbt "bijection-macros/console" | |
// paste the following | |
// Use :paste until the break below. | |
:paste | |
import com.twitter.bijection._ | |
import com.twitter.bijection.macros.common.TypesNotEqual | |
trait Semigroup[T] { |
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 scalaz._, Scalaz._ | |
import scalaz._ | |
import Scalaz._ | |
scala> import shapeless._, contrib.scalaz._, syntax.std.tuple._ | |
import shapeless._ | |
import contrib.scalaz._ | |
import syntax.std.tuple._ | |
scala> case class Thing(name: String, age: Long, size: Double) |
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._ | |
def foldRight[A, B](xs: List[A])(z: B)(f: (A, B) => B): B = | |
xs.foldLeft[B => TailRec[B]](done) { | |
case (acc, a) => (b: B) => tailcall(acc(f(a, b))) | |
}.apply(z).result |
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 { | |
trait Foo | |
object Foo { trait FooThing } | |
} |