Skip to content

Commit

Permalink
Merge pull request #30 from 47deg/formatting
Browse files Browse the repository at this point in the history
Use scalafmt for automatic formatting
  • Loading branch information
committed May 19, 2016
2 parents 9b997e2 + 5c07875 commit d99f57a
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 272 deletions.
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

0 comments on commit d99f57a

Please sign in to comment.