Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use scalafmt for automatic formatting #30

Merged
1 commit merged into from
May 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .scalafmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--style defaultWithAlign
--maxColumn 100
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ lazy val commonSettings = Seq(
"-language:higherKinds",
"-language:existentials",
"-language:postfixOps"
)
)
),
scalafmtConfig := Some(file(".scalafmt"))
) ++ reformatOnCompileSettings

lazy val allSettings = buildSettings ++ commonSettings

Expand All @@ -54,3 +55,4 @@ lazy val root = project.in(file("."))
publish := {},
publishLocal := {}
)

1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.8")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "1.5.1")
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.2.5")
8 changes: 4 additions & 4 deletions shared/src/main/scala/cache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

package fetch


/**
* A `Cache` trait so the users of the library can provide their own cache.
*/
* A `Cache` trait so the users of the library can provide their own cache.
*/
trait DataSourceCache {
def update[A](k: DataSourceIdentity, v: A): DataSourceCache

def get(k: DataSourceIdentity): Option[Any]

def cacheResults[I, A](results: Map[I, A], ds: DataSource[I, A]): DataSourceCache = {
def cacheResults[I, A](
results: Map[I, A], ds: DataSource[I, A]): DataSourceCache = {
results.foldLeft(this)({
case (acc, (i, a)) => acc.update(ds.identity(i), a)
})
Expand Down
8 changes: 4 additions & 4 deletions shared/src/main/scala/datasource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package fetch
import cats.Eval

/**
* A `DataSource` is the recipe for fetching a certain identity `I`, which yields
* results of type `A` with the concurrency and error handling specified by the Monad
* `M`.
*/
* A `DataSource` is the recipe for fetching a certain identity `I`, which yields
* results of type `A` with the concurrency and error handling specified by the Monad
* `M`.
*/
trait DataSource[I, A] {
def name: DataSourceName = this.toString
def identity(i: I): DataSourceIdentity = (name, i)
Expand Down
47 changes: 24 additions & 23 deletions shared/src/main/scala/env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package fetch
import scala.collection.immutable._

/**
* An environment that is passed along during the fetch rounds. It holds the
* cache and the list of rounds that have been executed.
*/
* An environment that is passed along during the fetch rounds. It holds the
* cache and the list of rounds that have been executed.
*/
trait Env {
def cache: DataSourceCache
def rounds: Seq[Round]
Expand All @@ -33,22 +33,22 @@ trait Env {
rounds.filterNot(_.cached)

def next(
newCache: DataSourceCache,
newRound: Round,
newIds: List[Any]
newCache: DataSourceCache,
newRound: Round,
newIds: List[Any]
): Env
}

/**
* A data structure that holds information about a fetch round.
*/
* A data structure that holds information about a fetch round.
*/
case class Round(
cache: DataSourceCache,
ds: DataSourceName,
kind: RoundKind,
startRound: Long,
endRound: Long,
cached: Boolean = false
cache: DataSourceCache,
ds: DataSourceName,
kind: RoundKind,
startRound: Long,
endRound: Long,
cached: Boolean = false
) {
def duration: Double = (endRound - startRound) / 1e6

Expand All @@ -64,17 +64,18 @@ final case class ManyRound(ids: List[Any]) extends RoundKind
final case class ConcurrentRound(ids: Map[String, List[Any]]) extends RoundKind

/**
* A concrete implementation of `Env` used in the default Fetch interpreter.
*/
* A concrete implementation of `Env` used in the default Fetch interpreter.
*/
case class FetchEnv(
cache: DataSourceCache,
ids: List[Any] = Nil,
rounds: Queue[Round] = Queue.empty
) extends Env {
cache: DataSourceCache,
ids: List[Any] = Nil,
rounds: Queue[Round] = Queue.empty
)
extends Env {
def next(
newCache: DataSourceCache,
newRound: Round,
newIds: List[Any]
newCache: DataSourceCache,
newRound: Round,
newIds: List[Any]
): FetchEnv =
copy(cache = newCache, rounds = rounds :+ newRound, ids = newIds)
}
Loading