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._ | |
import scala.concurrent._ | |
import java.util.concurrent.{Callable, FutureTask} | |
object Utils { | |
def toJavaFuture[TScalaType, TJavaType](f: Future[TScalaType])(map: (TScalaType => TJavaType))(implicit executor: ExecutionContext): java.util.concurrent.Future[TJavaType] = { | |
val applied = f.map(map) | |
val task = new FutureTask[TJavaType](new Callable[TJavaType] { | |
def call(): TJavaType = applied.value.get match { |
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
case class HystrixData(group: String, command: String, timeout: Int = 1000) | |
object Hystrix { | |
import com.netflix.hystrix._ | |
import rx.{Subscription, Subscriber} | |
import scala.concurrent.ExecutionContext | |
import scala.concurrent.{Promise, Future} | |
//B = return value or fallback | |
//A = optional value to call the hystrix command with |
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
// http://scastie.org/8089 | |
/*** | |
scalaVersion := "2.11.4" | |
libraryDependencies ++= Seq( | |
"io.spray" %% "spray-routing-shapeless2" % "1.3.2" | |
exclude("com.chuusai", "shapeless"), | |
"com.chuusai" %% "shapeless" % "2.1.0-RC2", | |
"com.typesafe.akka" %% "akka-actor" % "2.3.9" | |
) |
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
type MultiMap = Map[String, List[String]] | |
def formFieldMultiMap: Directive1[MultiMap] = { | |
requestInstance.flatMap[MultiMap :: HNil] { request => | |
import spray.httpx.unmarshalling._ | |
val result: Deserialized[MultiMap] = | |
request.as[HttpForm].right.flatMap { | |
case FormData(fields) => | |
val collected = fields.groupBy { case (k, _) => k } |
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
/** | |
* Provides a wrapper for by-name expressions with the intent that they can become eligible for | |
* implicit conversions and implicit resolution. | |
* | |
* @param expression A by-name parameter that will yield a result of type `T` when evaluated. | |
* @tparam T Result type of the evaluated `expression`. | |
*/ | |
final class ByName[+T](expression: => T) extends (() => T) { | |
/** | |
* Evaluates the given `expression` every time <em>without</em> memoizing the 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
case class UserId(value: String) extends AnyVal with slick.lifted.MappedTo[String] | |
case class User(id: UserId, userName: String, password: String) | |
trait UsersTable extends TableDefinition with TableSchema { provider: DriverProvider => | |
import driver.api._ | |
override type TableRecordType = User | |
override val table = TableQuery[TableDefinition] |
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 algebra._, std.int._ | |
import cats._, free._, Free._ | |
import scala.language.implicitConversions | |
trait Expr[A] | |
case class Const[A](term: A) extends Expr[A] | |
case class Add[A](e1: Expr[A], e2: Expr[A])(implicit val r: Ring[A]) extends Expr[A] | |
type Exp[A] = FreeC[Expr, 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 rx.lang.scala.{Subject, Observable} | |
import slick.backend.DatabasePublisher | |
import scala.concurrent.ExecutionContext | |
import scala.util.{Failure, Success} | |
trait StreamExtensions { | |
implicit def extendDatabasePublisher[T](publisher: DatabasePublisher[T]): StreamExtensions.DatabasePublisherExtensions[T] = | |
StreamExtensions.DatabasePublisherExtensions[T](publisher) | |
} |
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 shapeless._ | |
import cats.std.all._ | |
trait ShapelessCatsSemigroup { | |
implicit object HNilSemigroup extends Semigroup[HNil] { | |
override def combine(h1: HNil, h2: HNil): HNil = HNil | |
} | |
implicit def HListSemigroup[H : Semigroup, T <: HList : Semigroup]: Semigroup[H :: T] = | |
new Semigroup[H :: 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
import java.nio.ByteBuffer | |
import shapeless._ | |
trait OhcCodec[T] | |
extends OhcEncoder[T] | |
with OhcDecoder[T] | |
trait OhcEncoder[-T] { | |
def ohcEncode(given: T, buffer: ByteBuffer): Unit |
OlderNewer