Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #10 from tkrs/scalafmt
Browse files Browse the repository at this point in the history
Reformat with scalafmt
  • Loading branch information
tkrs authored Dec 21, 2019
2 parents 192dd54 + ae08ada commit 6f5079f
Show file tree
Hide file tree
Showing 36 changed files with 288 additions and 230 deletions.
9 changes: 9 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version=2.3.0
align.openParenCallSite = true
align.openParenDefnSite = true
maxColumn = 120
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
danglingParentheses = true
rewrite.rules = [AvoidInfix, SortImports, RedundantBraces, RedundantParens, SortModifiers]
docstrings = JavaDoc
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install:
script:
- |
if [[ "$TRAVIS_JDK_VERSION" = "openjdk11" && "$TRAVIS_SCALA_VERSION" = 2.13.* ]]; then
sbt ++$TRAVIS_SCALA_VERSION clean coverage compile test:compile test coverageReport coverageOff && codecov
sbt ++$TRAVIS_SCALA_VERSION clean coverage scalafmtCheckAll scalafmtSbtCheck compile test:compile test coverageReport coverageOff && codecov
else
sbt ++$TRAVIS_SCALA_VERSION clean compile test:compile test
fi
Expand Down
45 changes: 22 additions & 23 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
import scalariform.formatter.preferences._

val preferences =
ScalariformKeys.preferences := ScalariformKeys.preferences.value
.setPreference(DanglingCloseParenthesis, Force)

lazy val agni = project.in(file("."))
lazy val agni = project
.in(file("."))
.settings(allSettings)
.settings(noPublishSettings)
.aggregate(core, `twitter-util`, monix, `cats-effect`, examples)
Expand All @@ -14,8 +8,7 @@ lazy val agni = project.in(file("."))
lazy val allSettings = Seq.concat(
buildSettings,
baseSettings,
publishSettings,
Seq(preferences)
publishSettings
)

lazy val buildSettings = Seq(
Expand Down Expand Up @@ -45,7 +38,7 @@ lazy val testDeps = Seq(
"org.scalacheck" %% "scalacheck" % scalacheckVersion,
"org.scalatest" %% "scalatest" % scalatestVersion,
"org.mockito" % "mockito-core" % mockitoVersion
) map (_ % "test")
).map(_ % "test")

lazy val baseSettings = Seq(
scalacOptions ++= compilerOptions ++ {
Expand All @@ -62,7 +55,7 @@ lazy val baseSettings = Seq(
Resolver.sonatypeRepo("snapshots")
),
fork in Test := true,
scalacOptions in (Compile, console) ~= (_ filterNot (_ == "-Ywarn-unused:_"))
scalacOptions in (Compile, console) ~= (_.filterNot(_ == "-Ywarn-unused:_"))
)

lazy val publishSettings = Seq(
Expand All @@ -72,13 +65,13 @@ lazy val publishSettings = Seq(
licenses := Seq("MIT License" -> url("http://www.opensource.org/licenses/mit-license.php")),
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")
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"))
},
scmInfo := Some(
ScmInfo(
Expand Down Expand Up @@ -121,8 +114,8 @@ lazy val crossVersionSharedSources: Seq[Setting[_]] =
}
}


lazy val core = project.in(file("core"))
lazy val core = project
.in(file("core"))
.settings(allSettings)
.settings(crossVersionSharedSources)
.settings(
Expand All @@ -133,7 +126,8 @@ lazy val core = project.in(file("core"))
moduleName := "agni-core"
)

lazy val `twitter-util` = project.in(file("twitter-util"))
lazy val `twitter-util` = project
.in(file("twitter-util"))
.settings(allSettings)
.settings(
description := "agni twitter-util",
Expand All @@ -146,7 +140,8 @@ lazy val `twitter-util` = project.in(file("twitter-util"))
)
.dependsOn(core)

lazy val monix = project.in(file("monix"))
lazy val monix = project
.in(file("monix"))
.settings(allSettings)
.settings(
description := "agni monix",
Expand All @@ -160,7 +155,8 @@ lazy val monix = project.in(file("monix"))
)
.dependsOn(core)

lazy val `cats-effect` = project.in(file("cats-effect"))
lazy val `cats-effect` = project
.in(file("cats-effect"))
.settings(allSettings)
.settings(
description := "agni cats-effect",
Expand All @@ -173,7 +169,8 @@ lazy val `cats-effect` = project.in(file("cats-effect"))
)
.dependsOn(core)

lazy val benchmarks = project.in(file("benchmarks"))
lazy val benchmarks = project
.in(file("benchmarks"))
.settings(allSettings)
.settings(noPublishSettings)
.settings(
Expand All @@ -190,7 +187,8 @@ lazy val benchmarks = project.in(file("benchmarks"))
.enablePlugins(JmhPlugin)
.dependsOn(core % "test->test")

lazy val examples = project.in(file("examples"))
lazy val examples = project
.in(file("examples"))
.settings(allSettings)
.settings(noPublishSettings)
.settings(
Expand All @@ -210,7 +208,8 @@ lazy val examples = project.in(file("examples"))
lazy val compilerOptions = Seq(
"-target:jvm-1.8",
"-deprecation",
"-encoding", "UTF-8",
"-encoding",
"UTF-8",
"-unchecked",
"-feature",
"-language:existentials",
Expand Down
39 changes: 20 additions & 19 deletions cats-effect/src/main/scala/agni/catsEffect/async.scala
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
package agni.catsEffect

import java.util.concurrent.{ CompletableFuture, CompletionStage }
import java.util.concurrent.{CompletableFuture, CompletionStage}
import java.util.function.BiConsumer

import agni.util.Par
import cats.effect.ConcurrentEffect
import cats.~>

object async {
implicit def catsConcurrentEffectPar[F[_]](implicit F: ConcurrentEffect[F]): Par.Aux[CompletionStage, F] = new Par[CompletionStage] {
type G[A] = F[A]
implicit def catsConcurrentEffectPar[F[_]](implicit F: ConcurrentEffect[F]): Par.Aux[CompletionStage, F] =
new Par[CompletionStage] {
type G[A] = F[A]

def parallel: CompletionStage ~> G = λ[CompletionStage ~> G](run(_))
def parallel: CompletionStage ~> G = λ[CompletionStage ~> G](run(_))

private[this] def run[A](fa: CompletionStage[A]): G[A] = {
def f(cb: Either[Throwable, A] => Unit) =
fa.whenComplete(new BiConsumer[A, Throwable] {
def accept(t: A, u: Throwable): Unit =
if (u != null) cb(Left(u)) else cb(Right(t))
})
private[this] def run[A](fa: CompletionStage[A]): G[A] = {
def f(cb: Either[Throwable, A] => Unit) =
fa.whenComplete(new BiConsumer[A, Throwable] {
def accept(t: A, u: Throwable): Unit =
if (u != null) cb(Left(u)) else cb(Right(t))
})

fa match {
case faa: CompletableFuture[_] =>
F.cancelable { cb =>
f(cb)
F.delay(faa.cancel(false))
}
case _ =>
F.async(f)
fa match {
case faa: CompletableFuture[_] =>
F.cancelable { cb =>
f(cb)
F.delay(faa.cancel(false))
}
case _ =>
F.async(f)
}
}
}
}
}
2 changes: 1 addition & 1 deletion cats-effect/src/test/scala/agni/catsEffect/AsyncSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.util.concurrent.CompletionStage
import java.util.function.Supplier

import agni.util.Par
import cats.effect.{ ContextShift, IO }
import cats.effect.{ContextShift, IO}
import org.scalatest._

import scala.concurrent.duration._
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/agni/Binder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ object Binder extends TupleBinder {

implicit def bindSingle[A](implicit serializeA: RowSerializer[A]): Binder[A] =
(bound, version, a) => serializeA(bound, 0, a, version)
}
}
2 changes: 1 addition & 1 deletion core/src/main/scala/agni/Cql.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util.concurrent.CompletionStage

import agni.util.Par
import agni.internal.Pageable
import cats.{ Apply, MonadError }
import cats.{Apply, MonadError}
import cats.syntax.functor._
import cats.syntax.applicative._
import cats.syntax.flatMap._
Expand Down
16 changes: 9 additions & 7 deletions core/src/main/scala/agni/Deserializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package agni

import java.net.InetAddress
import java.nio.ByteBuffer
import java.time.{ Instant, LocalDate }
import java.time.{Instant, LocalDate}
import java.util.UUID

import agni.internal.ScalaVersionSpecifics._
Expand Down Expand Up @@ -43,10 +43,11 @@ object Deserializer {
override def apply(raw: ByteBuffer, version: ProtocolVersion): Either[Throwable, A] = Left(ex)
}

implicit def deserializeOption[A](implicit A: Deserializer[A]): Deserializer[Option[A]] = new Deserializer[Option[A]] {
override def apply(raw: ByteBuffer, version: ProtocolVersion): Either[Throwable, Option[A]] =
if (raw == null) Right(None) else A.apply(raw, version).map(Some(_))
}
implicit def deserializeOption[A](implicit A: Deserializer[A]): Deserializer[Option[A]] =
new Deserializer[Option[A]] {
override def apply(raw: ByteBuffer, version: ProtocolVersion): Either[Throwable, Option[A]] =
if (raw == null) Right(None) else A.apply(raw, version).map(Some(_))
}

implicit val deserializeAscii: Deserializer[String] = new Deserializer[String] {
override def apply(raw: ByteBuffer, version: ProtocolVersion): Either[Throwable, String] =
Expand Down Expand Up @@ -164,7 +165,7 @@ object Deserializer {
builder += k -> v
} match {
case Right(_) => go(size - 1)
case Left(e) => Left(e)
case Left(e) => Left(e)
}
}

Expand All @@ -176,7 +177,8 @@ object Deserializer {
}
}

implicit def deserializeCollection[A, C[_]](implicit A: Deserializer[A], factory: Factory[A, C[A]]): Deserializer[C[A]] =
implicit def deserializeCollection[A, C[_]](implicit A: Deserializer[A],
factory: Factory[A, C[A]]): Deserializer[C[A]] =
new Deserializer[C[A]] {
override def apply(raw: ByteBuffer, version: ProtocolVersion): Either[Throwable, C[A]] = {
val builder = factory.newBuilder
Expand Down
22 changes: 12 additions & 10 deletions core/src/main/scala/agni/RowDeserializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package agni
import cats.syntax.either._
import com.datastax.oss.driver.api.core.ProtocolVersion
import com.datastax.oss.driver.api.core.cql.Row
import com.datastax.oss.driver.api.core.data.{ TupleValue, UdtValue }
import com.datastax.oss.driver.api.core.data.{TupleValue, UdtValue}

trait RowDeserializer[A] {
def apply(row: Row, i: Int, version: ProtocolVersion): Either[Throwable, A]
Expand All @@ -15,15 +15,17 @@ object RowDeserializer {
def apply[A](implicit A: RowDeserializer[A]): RowDeserializer[A] = A

implicit def builtIn[A](implicit A: Deserializer[A]): RowDeserializer[A] = new RowDeserializer[A] {
override def apply(row: Row, i: Int, version: ProtocolVersion): Either[Throwable, A] = for {
v <- Either.catchNonFatal(row.getBytesUnsafe(i))
r <- A(v, version)
} yield r

override def apply(row: Row, name: String, version: ProtocolVersion): Either[Throwable, A] = for {
v <- Either.catchNonFatal(row.getBytesUnsafe(name))
r <- A(v, version)
} yield r
override def apply(row: Row, i: Int, version: ProtocolVersion): Either[Throwable, A] =
for {
v <- Either.catchNonFatal(row.getBytesUnsafe(i))
r <- A(v, version)
} yield r

override def apply(row: Row, name: String, version: ProtocolVersion): Either[Throwable, A] =
for {
v <- Either.catchNonFatal(row.getBytesUnsafe(name))
r <- A(v, version)
} yield r
}

implicit val tupleValue: RowDeserializer[TupleValue] = new RowDeserializer[TupleValue] {
Expand Down
32 changes: 25 additions & 7 deletions core/src/main/scala/agni/RowSerializer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cats.syntax.either._
import cats.syntax.flatMap._
import com.datastax.oss.driver.api.core.ProtocolVersion
import com.datastax.oss.driver.api.core.cql.BoundStatement
import com.datastax.oss.driver.api.core.data.{ TupleValue, UdtValue }
import com.datastax.oss.driver.api.core.data.{TupleValue, UdtValue}

trait RowSerializer[A] {
def apply(bound: BoundStatement, i: Int, a: A, version: ProtocolVersion): Either[Throwable, BoundStatement]
Expand All @@ -17,28 +17,46 @@ object RowSerializer {
def apply[A](implicit A: RowSerializer[A]): RowSerializer[A] = A

implicit def builtIn[A](implicit A: Serializer[A]): RowSerializer[A] = new RowSerializer[A] {
override def apply(bound: BoundStatement, i: Int, a: A, version: ProtocolVersion): Either[Throwable, BoundStatement] =
override def apply(bound: BoundStatement,
i: Int,
a: A,
version: ProtocolVersion): Either[Throwable, BoundStatement] =
A.apply(a, version) >>=
(bs => Either.catchNonFatal(bound.setBytesUnsafe(i, bs)))

override def apply(bound: BoundStatement, name: String, a: A, version: ProtocolVersion): Either[Throwable, BoundStatement] =
override def apply(bound: BoundStatement,
name: String,
a: A,
version: ProtocolVersion): Either[Throwable, BoundStatement] =
A.apply(a, version) >>=
(bs => Either.catchNonFatal(bound.setBytesUnsafe(name, bs)))
}

implicit val tupleValue: RowSerializer[TupleValue] = new RowSerializer[TupleValue] {
override def apply(bound: BoundStatement, i: Int, a: TupleValue, version: ProtocolVersion): Either[Throwable, BoundStatement] =
override def apply(bound: BoundStatement,
i: Int,
a: TupleValue,
version: ProtocolVersion): Either[Throwable, BoundStatement] =
Either.catchNonFatal(bound.setTupleValue(i, a))

override def apply(bound: BoundStatement, name: String, a: TupleValue, version: ProtocolVersion): Either[Throwable, BoundStatement] =
override def apply(bound: BoundStatement,
name: String,
a: TupleValue,
version: ProtocolVersion): Either[Throwable, BoundStatement] =
Either.catchNonFatal(bound.setTupleValue(name, a))
}

implicit val udtValue: RowSerializer[UdtValue] = new RowSerializer[UdtValue] {
override def apply(bound: BoundStatement, i: Int, a: UdtValue, version: ProtocolVersion): Either[Throwable, BoundStatement] =
override def apply(bound: BoundStatement,
i: Int,
a: UdtValue,
version: ProtocolVersion): Either[Throwable, BoundStatement] =
Either.catchNonFatal(bound.setUdtValue(i, a))

override def apply(bound: BoundStatement, name: String, a: UdtValue, version: ProtocolVersion): Either[Throwable, BoundStatement] =
override def apply(bound: BoundStatement,
name: String,
a: UdtValue,
version: ProtocolVersion): Either[Throwable, BoundStatement] =
Either.catchNonFatal(bound.setUdtValue(name, a))
}
}
Loading

0 comments on commit 6f5079f

Please sign in to comment.