Skip to content

Instantly share code, notes, and snippets.

View btrofimov's full-sized avatar

Boris Trofimov btrofimov

View GitHub Profile
@btrofimov
btrofimov / build.sbt
Created December 15, 2016 11:00 — forked from seratch/build.sbt
Scala School - Testing with specs2 examples
organization := "net.seratch"
name := "sandbox"
version := "0.1"
scalaVersion := "2.9.1"
libraryDependencies ++= Seq(
"junit" % "junit" % "4.9" withSources(),
@btrofimov
btrofimov / left.scala
Created October 24, 2016 08:07 — forked from HerringtonDarkholme/left.scala
foldLeft and foldRight
def retry(noTimes: Int)(block: ⇒Future[T]): Future[T] = {
val ns: Iterator[Int] = (1 to noTimes).iterator
val attempts: Iterator[Future[T]] = ns.map(_⇒ ()⇒block)
val failed = Future.failed(new Exception)
attempts.foldLeft(failed)
((a,block) ⇒ a recoverWith { block() })
}
retry(3) { block }
= unfolds to
package com.vast.example
import java.net.InetSocketAddress
import java.util.UUID
import java.util.concurrent.{Executors, TimeUnit}
import com.google.common.base.Splitter
import com.twitter.finagle.http.Http
import com.twitter.finagle.builder.{Server, ServerBuilder}
import com.twitter.finagle.service.TimeoutFilter
import com.twitter.finagle.{Service, SimpleFilter, GlobalRequestTimeoutException}