Skip to content

Instantly share code, notes, and snippets.

View travisbrown's full-sized avatar
😎
In hiding

Travis Brown travisbrown

😎
In hiding
View GitHub Profile
@travisbrown
travisbrown / finagle-client-timeout-example.scala
Created August 27, 2014 15:40
Simple example contrasting a client with baked-in timeout functionality and a client composed with a timeout filter.
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)
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
scalaVersion := "2.11.2"
libraryDependencies += "com.chuusai" %% "shapeless" % "2.0.0"
name := "Observe Sample"
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) }
}
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)"
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
// 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] {
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)
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
package demo {
trait Foo
object Foo { trait FooThing }
}