name := "finch-quickstart"
version := "0.0.0"
scalaVersion := "2.11.5"
libraryDependencies ++= Seq(
"com.github.finagle" %% "finch-core" % "0.4.0"
)
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
/** | |
* This is an immutable builder patter implemented in Scala within OO style. | |
* | |
* There is might be a better approach (i.e., pattern matching, case classes, etc) | |
* in implementing this idea within FP style, but the overall picture is robust: | |
* | |
* (a) there is no mutable state | |
* (b) it's a pure FSM (Finite State Machine) | |
* | |
* I'll try to keep this gist updated along with any new ideas regarding this |
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
/** | |
* Reactive Converter of Scala's Future[A] object to com.twitter.util.Future[A] object. | |
* | |
* Usage: | |
* | |
* val s = new Service[Req, Rep] with FutureConverter { | |
* def apply(req: Req): Future[Rep] = { | |
* val f = ... // a Scala Future | |
* f.toTwitterFuture | |
* } |
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
/** | |
* All the magic is done by Scala compiler. | |
*/ | |
trait ImplicitMongoConnection[A] { | |
def withConnection(block: MongoConnection => A) | |
(implicit connection: MongoConnection): A = block(s) | |
} | |
/** | |
* This might be a separate file with service implementation. |
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
val routes = User.routes orElse | |
Order.routes | |
// would be great having: | |
// val backend = RoutingService.byMethodAndPathObjct(routes) | |
val backend = new RoutingService( | |
new PartialFunction[Request, Service[Request, Response]] { | |
def apply(req: Request) = routes((req.method, Path(req.path))) | |
def isDefinedAt(req: Request) = routes.isDefinedAt((req.method), Path(req.path)) | |
} |
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
val energy = Console.readLine().toInt | |
val streams: List[(Int, Int, Int)] = | |
Iterator.continually(Console.readLine).takeWhile(_.nonEmpty).map { s: String => | |
val stream = s.split(" ") | |
(stream(0).toInt, stream(1).toInt, stream(2).toInt) | |
} toList | |
val (_, end, _) = streams.maxBy { | |
case (_, to, _) => to |
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 R[I, O] { def apply(i: I): O } // reader | |
trait ToString[I] { def apply(i: I): String } // converter | |
case class Foo(s: String) { | |
def apply[I](implicit toStr: ToString[I]): R[I, String] = new R[I, String] { | |
def apply(i: I) = s + toStr(i) | |
} | |
def apply[I](i: I)(implicit toStr: ToString[I]): String = (apply(toStr))(i) | |
} |
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 F[A] { | |
def apply(foo: Foo): X[A] | |
def map(fn: A => B): F[B] | |
def flatMap(fn: A => F[B]): F[B] | |
def fooMap(fn: A => X[B]): F[B] // how is this called? constMap? | |
} |
There is a bunch of tickets/PRs related to the same underlying problem. It has started with two tickets:
- [Issue 190][0] - composing routers with filters and services
- [Issue 172][1] - mixing futures and services in the same endpoint/router
Then Jens has created a [PR 184][2] that indicated a problem of domain types in Finch. So, I created an [issue 204][3] to track the progress on this direction. More importantly, I've posted a first version of possible solution for the "Finch in Action" problem in [PR 206][4]. This document mostly describes an approach called "Micro Finch", that in my opinion solves the original problem.
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
// A type for a composite value | |
case class ~[+A, +B](a: A, b: B) | |
// An applicative functor | |
trait F[+A] { self => | |
def value: A | |
def ~[B](that: F[B]): F[A ~ B] = new F[A ~ B] { | |
def value: A ~ B = new ~(self.value, that.value) | |
} | |
} |
OlderNewer