Skip to content
Permalink
Browse files

Run formatter

  • Loading branch information...
travisbrown committed May 31, 2019
1 parent e9fe9e6 commit 6b8be1fee018ce6193d4cf82045be79136ca21bf
@@ -39,9 +39,11 @@ class RerunnableBenchmark {

@Benchmark
def sumIntsR: Int = Await.result(
numbers.foldLeft(Rerunnable(0)) {
case (acc, i) => acc.flatMap(prev => Rerunnable(prev + i))
}.run
numbers
.foldLeft(Rerunnable(0)) {
case (acc, i) => acc.flatMap(prev => Rerunnable(prev + i))
}
.run
)

@Benchmark
@@ -53,8 +55,10 @@ class RerunnableBenchmark {

@Benchmark
def sumIntsPR: Int = Await.result(
numbers.foldLeft(Rerunnable.withFuturePool(pool)(0)) {
case (acc, i) => acc.flatMap(prev => Rerunnable.withFuturePool(pool)(prev + i))
}.run
numbers
.foldLeft(Rerunnable.withFuturePool(pool)(0)) {
case (acc, i) => acc.flatMap(prev => Rerunnable.withFuturePool(pool)(prev + i))
}
.run
)
}
@@ -9,7 +9,8 @@ organization in ThisBuild := "io.catbird"

val compilerOptions = Seq(
"-deprecation",
"-encoding", "UTF-8",
"-encoding",
"UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
@@ -47,7 +48,8 @@ lazy val baseSettings = Seq(

lazy val allSettings = baseSettings ++ publishSettings

lazy val root = project.in(file("."))
lazy val root = project
.in(file("."))
.enablePlugins(GhpagesPlugin, ScalaUnidocPlugin)
.settings(allSettings ++ noPublishSettings)
.settings(
@@ -122,13 +124,15 @@ lazy val publishSettings = Seq(
licenses := Seq("Apache 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := { _ => false },
pomIncludeRepository := { _ =>
false
},
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
autoAPIMappings := true,
apiURL := Some(url("https://travisbrown.github.io/catbird/api/")),
@@ -159,10 +163,11 @@ credentials ++= (
for {
username <- Option(System.getenv().get("SONATYPE_USERNAME"))
password <- Option(System.getenv().get("SONATYPE_PASSWORD"))
} yield Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
username,
password
)
} yield
Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
username,
password
)
).toSeq
@@ -15,31 +15,35 @@ trait RerunnableInstances {
override final def delay[A](thunk: => A): Rerunnable[A] = Rerunnable[A](thunk)

final def async[A](k: (Either[Throwable, A] => Unit) => Unit): Rerunnable[A] =
new Rerunnable[A] {
final def run: Future[A] = {
val promise = new Promise[A]
new Rerunnable[A] {
final def run: Future[A] = {
val promise = new Promise[A]

k { e =>
if (promise.isDefined) () else e match {
case Right(a) => promise.setValue(a)
case Left(err) => promise.setException(err)
k { e =>
if (promise.isDefined) ()
else
e match {
case Right(a) => promise.setValue(a)
case Left(err) => promise.setException(err)
}
}
}

promise
promise
}
}
}

final def asyncF[A](k: (Either[Throwable, A] => Unit) => Rerunnable[Unit]): Rerunnable[A] =
new Rerunnable[A] {
final def run: Future[A] = {
val promise = new Promise[A]

val rerunnable = k { e =>
if (promise.isDefined) () else e match {
case Right(a) => promise.setValue(a)
case Left(err) => promise.setException(err)
}
if (promise.isDefined) ()
else
e match {
case Right(a) => promise.setValue(a)
case Left(err) => promise.setException(err)
}
}

rerunnable.run.flatMap(_ => promise)
@@ -56,7 +60,7 @@ trait RerunnableInstances {
acquire.run.flatMap { a =>
val future = use(a).run
future.transform {
case Return(b) => release(a, ExitCase.complete).run.flatMap(_ => future)
case Return(b) => release(a, ExitCase.complete).run.flatMap(_ => future)
case Throw(err) => release(a, ExitCase.error(err)).run.flatMap(_ => future)
}
}
@@ -8,7 +8,7 @@ import scala.util.{ Left, Right }
package object effect extends RerunnableInstances {
def futureToAsync[F[_], A](fa: => Future[A])(implicit F: Async[F]): F[A] = F.async { k =>
fa.respond {
case Return(a) => k(Right[Throwable, A](a))
case Return(a) => k(Right[Throwable, A](a))
case Throw(err) => k(Left[Throwable, A](err))
}
}
@@ -9,8 +9,7 @@ import com.twitter.finagle.Service
import org.scalatest.FunSuite
import org.typelevel.discipline.scalatest.Discipline

class ServiceSuite extends FunSuite with Discipline with
ServiceInstances with ArbitraryInstances with EqInstances {
class ServiceSuite extends FunSuite with Discipline with ServiceInstances with ArbitraryInstances with EqInstances {
implicit val eq: Eq[Service[Int, Int]] = serviceEq(1.second)

checkAll("Service", CategoryTests[Service].compose[Int, Int, Int, Int])
@@ -15,7 +15,7 @@ abstract class Rerunnable[+A] { self =>

final def fa: Rerunnable[A] = self
final def ff: Try[A] => Rerunnable[B] = {
case Return(a) => Rerunnable.const[B](f(a))
case Return(a) => Rerunnable.const[B](f(a))
case Throw(error) => Rerunnable.raiseError[B](error)
}
}
@@ -25,7 +25,7 @@ abstract class Rerunnable[+A] { self =>

final def fa: Rerunnable[A] = self
final def ff: Try[A] => Rerunnable[B] = {
case Return(a) => f(a)
case Return(a) => f(a)
case Throw(error) => Rerunnable.raiseError[B](error)
}
}
@@ -39,15 +39,16 @@ abstract class Rerunnable[+A] { self =>

final def fa: Rerunnable[A] = self
final def ff: Try[A] => Rerunnable[(A, B)] = {
case Return(a) => new Rerunnable.Bind[(A, B)] {
type P = B

final def fa: Rerunnable[B] = other
final def ff: Try[B] => Rerunnable[(A, B)] = {
case Return(b) => Rerunnable.const((a, b))
case Throw(error) => Rerunnable.raiseError[(A, B)](error)
case Return(a) =>
new Rerunnable.Bind[(A, B)] {
type P = B

final def fa: Rerunnable[B] = other
final def ff: Try[B] => Rerunnable[(A, B)] = {
case Return(b) => Rerunnable.const((a, b))
case Throw(error) => Rerunnable.raiseError[(A, B)](error)
}
}
}
case Throw(error) => Rerunnable.raiseError[(A, B)](error)
}
}
@@ -68,12 +69,13 @@ final object Rerunnable extends RerunnableInstances1 {
final type P = inner.P

final def fa: Rerunnable[P] = inner.fa
final def ff: Try[P] => Rerunnable[B] = p => new Bind[B] {
final type P = bind.P
final def ff: Try[P] => Rerunnable[B] = p =>
new Bind[B] {
final type P = bind.P

final val fa: Rerunnable[P] = inner.ff(p)
final val ff: Try[P] => Rerunnable[B] = bind.ff
}
final val fa: Rerunnable[P] = inner.ff(p)
final val ff: Try[P] => Rerunnable[B] = bind.ff
}
}

reassociate(next)
@@ -170,19 +172,18 @@ private[util] class RerunnableMonadError extends MonadError[Rerunnable, Throwabl
}

override final def attempt[A](fa: Rerunnable[A]): Rerunnable[Either[Throwable, A]] = fa.liftToTry.map {
case Return(a) => Right[Throwable, A](a)
case Return(a) => Right[Throwable, A](a)
case Throw(err) => Left[Throwable, A](err)
}

final def tailRecM[A, B](a: A)(f: A => Rerunnable[Either[A, B]]): Rerunnable[B] = f(a).flatMap {
case Right(b) => pure(b)
case Right(b) => pure(b)
case Left(nextA) => tailRecM(nextA)(f)
}
}

private[util] sealed class RerunnableSemigroup[A](implicit A: Semigroup[A])
extends Semigroup[Rerunnable[A]] {
final def combine(fx: Rerunnable[A], fy: Rerunnable[A]): Rerunnable[A] = fx.product(fy).map {
case (x, y) => A.combine(x, y)
}
private[util] sealed class RerunnableSemigroup[A](implicit A: Semigroup[A]) extends Semigroup[Rerunnable[A]] {
final def combine(fx: Rerunnable[A], fy: Rerunnable[A]): Rerunnable[A] = fx.product(fy).map {
case (x, y) => A.combine(x, y)
}
}
@@ -36,7 +36,7 @@ trait AsyncStreamInstances1 {

private[util] class AsyncStreamSemigroup[A](implicit A: Semigroup[A]) extends Semigroup[AsyncStream[A]] {
final def combine(fa: AsyncStream[A], fb: AsyncStream[A]): AsyncStream[A] = fa.flatMap { a =>
fb.map( b => A.combine(a,b) )
fb.map(b => A.combine(a, b))
}

}
@@ -24,7 +24,7 @@ trait FutureInstances extends FutureInstances1 {
final def raiseError[A](e: Throwable): Future[A] = Future.exception(e)

final def tailRecM[A, B](a: A)(f: A => Future[Either[A, B]]): Future[B] = f(a).flatMap {
case Right(b) => pure(b)
case Right(b) => pure(b)
case Left(nextA) => tailRecM(nextA)(f)
}
}
@@ -62,9 +62,8 @@ private[util] sealed abstract class FutureCoflatMap extends CoflatMap[Future] {
final def coflatMap[A, B](fa: Future[A])(f: Future[A] => B): Future[B] = Future(f(fa))
}

private[util] sealed class FutureSemigroup[A](implicit A: Semigroup[A])
extends Semigroup[Future[A]] {
final def combine(fx: Future[A], fy: Future[A]): Future[A] = fx.join(fy).map {
case (x, y) => A.combine(x, y)
}
private[util] sealed class FutureSemigroup[A](implicit A: Semigroup[A]) extends Semigroup[Future[A]] {
final def combine(fx: Future[A], fy: Future[A]): Future[A] = fx.join(fy).map {
case (x, y) => A.combine(x, y)
}
}
@@ -11,9 +11,9 @@ trait TryInstances extends TryInstances1 {
implicit final def twitterTryEq[A](implicit A: Eq[A], T: Eq[Throwable]): Eq[Try[A]] =
new Eq[Try[A]] {
def eqv(x: Try[A], y: Try[A]): Boolean = (x, y) match {
case (Throw(xError), Throw(yError)) => T.eqv(xError, yError)
case (Throw(xError), Throw(yError)) => T.eqv(xError, yError)
case (Return(xValue), Return(yValue)) => A.eqv(xValue, yValue)
case _ => false
case _ => false
}
}

@@ -35,21 +35,21 @@ trait TryInstances extends TryInstances1 {

final def foldLeft[A, B](fa: Try[A], b: B)(f: (B, A) => B): B = fa match {
case Return(a) => f(b, a)
case Throw(_) => b
case Throw(_) => b
}

final def foldRight[A, B](fa: Try[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] = fa match {
case Return(a) => f(a, lb)
case Throw(_) => lb
case Throw(_) => lb
}

final def traverse[G[_], A, B](fa: Try[A])(f: A => G[B])(implicit G: Applicative[G]): G[Try[B]] = fa match {
case Return(a) => G.map(f(a))(Return(_))
case Return(a) => G.map(f(a))(Return(_))
case t: Throw[_] => G.pure(TryInstances.castThrow[B](t))
}

@tailrec final def tailRecM[A, B](a: A)(f: A => Try[Either[A, B]]): Try[B] = f(a) match {
case t: Throw[_] => TryInstances.castThrow[B](t)
case t: Throw[_] => TryInstances.castThrow[B](t)
case Return(Left(a1)) => tailRecM(a1)(f)
case Return(Right(b)) => Return(b)
}
@@ -4,7 +4,7 @@ package util
import cats.Eq
import cats.instances.int._
import cats.instances.tuple._
import cats.kernel.laws.discipline.{MonoidTests, SemigroupTests}
import cats.kernel.laws.discipline.{ MonoidTests, SemigroupTests }
import cats.laws.discipline._
import com.twitter.concurrent.AsyncStream
import com.twitter.conversions.DurationOps._
@@ -15,10 +15,10 @@ class AsyncStreamSuite extends FunSuite with Discipline with AsyncStreamInstance

implicit val eqAsyncStreamInt: Eq[AsyncStream[Int]] = asyncStreamEq(1.second)
implicit val eqAsyncStreamAsyncStreamInt: Eq[AsyncStream[AsyncStream[Int]]] = asyncStreamEq(1.second)
implicit val eqAsyncStreamIntIntInt: Eq[AsyncStream[(Int,Int,Int)]] = asyncStreamEq[(Int,Int,Int)](1.second)
implicit val eqAsyncStreamIntIntInt: Eq[AsyncStream[(Int, Int, Int)]] = asyncStreamEq[(Int, Int, Int)](1.second)

checkAll("AsyncStream[Int]", MonadTests[AsyncStream].monad[Int, Int, Int])
checkAll("AsyncStream[Int]", SemigroupTests[AsyncStream[Int]](asyncStreamSemigroup[Int]).semigroup)
checkAll("AsyncStream[Int]", MonoidTests[AsyncStream[Int]].monoid)

}

0 comments on commit 6b8be1f

Please sign in to comment.
You can’t perform that action at this time.