Skip to content

Commit

Permalink
Bump sbt-scalafmt to 2.4.6 (close #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Feb 9, 2022
1 parent d01b47e commit a02687e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 69 deletions.
4 changes: 3 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
version = 3.4.2
runner.dialect = scala213
style = defaultWithAlign
maxColumn = 100

docstrings = JavaDoc
docstrings.style = Asterisk
optIn.breakChainOnFirstMethodDot = true
spaces.afterKeywordBeforeParen = true
continuationIndent.defnSite = 2
Expand Down
12 changes: 6 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
lazy val root = project
.in(file("."))
.settings(
organization := "com.snowplowanalytics",
name := "scala-lru-map",
version := "0.5.0",
description := "Simple LRU Map for caching",
scalaVersion := "2.13.8",
organization := "com.snowplowanalytics",
name := "scala-lru-map",
version := "0.5.0",
description := "Simple LRU Map for caching",
scalaVersion := "2.13.8",
crossScalaVersions := Seq("2.12.15", "2.13.8"),
javacOptions := BuildSettings.javaCompilerOptions,
javacOptions := BuildSettings.javaCompilerOptions,
libraryDependencies ++= Seq(
Dependencies.cats,
Dependencies.catsEffect,
Expand Down
23 changes: 13 additions & 10 deletions project/BuildSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ import scoverage.ScoverageKeys._
object BuildSettings {

lazy val publishSettings = bintraySettings ++ Seq(
publishMavenStyle := true,
publishArtifact := true,
publishMavenStyle := true,
publishArtifact := true,
publishArtifact in Test := false,
licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.html")),
bintrayOrganization := Some("snowplow"),
bintrayRepository := "snowplow-maven",
bintrayOrganization := Some("snowplow"),
bintrayRepository := "snowplow-maven",
pomIncludeRepository := { _ => false },
homepage := Some(url("https://github.com/snowplow-incubator/scala-lru-map")),
scmInfo := Some(ScmInfo(url("https://github.com/snowplow-incubator/scala-lru-map"),
"scm:git@github.com:snowplow-incubator/scala-lru-map.git")),
pomExtra := (
<developers>
homepage := Some(url("https://github.com/snowplow-incubator/scala-lru-map")),
scmInfo := Some(
ScmInfo(
url("https://github.com/snowplow-incubator/scala-lru-map"),
"scm:git@github.com:snowplow-incubator/scala-lru-map.git"
)
),
pomExtra := (<developers>
<developer>
<name>Snowplow Analytics Ltd</name>
<email>support@snowplowanalytics.com</email>
Expand All @@ -53,7 +56,7 @@ object BuildSettings {
)

lazy val docSettings = Seq(
gitRemoteRepo := "https://github.com/snowplow-incubator/scala-lru-map.git",
gitRemoteRepo := "https://github.com/snowplow-incubator/scala-lru-map.git",
siteSubdirName := ""
)

Expand Down
10 changes: 5 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import sbt._

object Dependencies {
val cats = "org.typelevel" %% "cats-core" % "2.7.0"
val catsEffect = "org.typelevel" %% "cats-effect" % "3.3.5"
val scaffeine = "com.github.blemale" %% "scaffeine" % "5.1.2"
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.15.4" % Test
val specs2 = "org.specs2" %% "specs2-core" % "4.13.2" % Test
val cats = "org.typelevel" %% "cats-core" % "2.7.0"
val catsEffect = "org.typelevel" %% "cats-effect" % "3.3.5"
val scaffeine = "com.github.blemale" %% "scaffeine" % "5.1.2"
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.15.4" % Test
val specs2 = "org.specs2" %% "specs2-core" % "4.13.2" % Test
}
14 changes: 7 additions & 7 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.3")
addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15")
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.3.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.12")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.3")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.3.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.12")
49 changes: 26 additions & 23 deletions src/main/scala/com.snowplowanalytics.lrumap/CreateLruMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ import cats.effect.Async
import cats.syntax.functor._
import com.github.blemale.scaffeine.Scaffeine

/** `CreateLruMap` provides an ability to initialize the cache,
* which effect will `F`
*
* *WARNING*: Due to support of non-`Sync`/eager algebras,
* users should be super-careful about creating *values* of `F[_]`,
* as they won't have RT/lazy semantics and will be memoized
*
* This is NOT a type class, as it does not have the coherence
* requirement, but can be passed implicitly
*/
/**
* `CreateLruMap` provides an ability to initialize the cache, which effect will `F`
*
* *WARNING*: Due to support of non-`Sync`/eager algebras, users should be super-careful about
* creating *values* of `F[_]`, as they won't have RT/lazy semantics and will be memoized
*
* This is NOT a type class, as it does not have the coherence requirement, but can be passed
* implicitly
*/
trait CreateLruMap[F[_], K, V] extends Serializable {
/** Create an LruMap within `F` effect
*
* @param size Max size before evicting
*/

/**
* Create an LruMap within `F` effect
*
* @param size
* Max size before evicting
*/
def create(size: Int): F[LruMap[F, K, V]]
}

Expand All @@ -46,23 +48,24 @@ object CreateLruMap {

private val underlying = makeUnderlying[K, V](size)

def get(key: K): Id[Option[V]] = underlying.getIfPresent(key)
def get(key: K): Id[Option[V]] = underlying.getIfPresent(key)
def put(key: K, value: V): Id[Unit] = underlying.put(key, value)
}
}

/** Pure instance */
implicit def asyncInitCache[F[_], K, V](implicit F: Async[F]): CreateLruMap[F, K, V] = new CreateLruMap[F, K, V] {
implicit def asyncInitCache[F[_], K, V](implicit F: Async[F]): CreateLruMap[F, K, V] =
new CreateLruMap[F, K, V] {

def create(size: Int): F[LruMap[F, K, V]] =
F.delay(makeUnderlying[K, V](size)).map { underlying =>
new LruMap[F, K, V] {
def get(key: K): F[Option[V]] = F.delay(underlying.getIfPresent(key))
def create(size: Int): F[LruMap[F, K, V]] =
F.delay(makeUnderlying[K, V](size)).map { underlying =>
new LruMap[F, K, V] {
def get(key: K): F[Option[V]] = F.delay(underlying.getIfPresent(key))

def put(key: K, value: V): F[Unit] = F.delay(underlying.put(key, value))
def put(key: K, value: V): F[Unit] = F.delay(underlying.put(key, value))
}
}
}
}
}

private def makeUnderlying[K, V](maxSize: Int) = {
Scaffeine()
Expand Down
9 changes: 5 additions & 4 deletions src/main/scala/com.snowplowanalytics.lrumap/LruMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ package com.snowplowanalytics.lrumap

/** Pure cache interface with `F` effect produced by interactions with cache */
trait LruMap[F[_], K, V] {

/**
* Associates the key with the specified value
*/
* Associates the key with the specified value
*/
def put(key: K, value: V): F[Unit]

/**
* Returns the value associated with the key, unless the key has been evicted
*/
* Returns the value associated with the key, unless the key has been evicted
*/
def get(key: K): F[Option[V]]
}
30 changes: 17 additions & 13 deletions src/test/scala/com.snowplowanalytics.lrumap/LruMapTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package com.snowplowanalytics.lrumap

import org.scalacheck.{Properties, Prop, Gen}
import org.scalacheck.{Gen, Prop, Properties}
import cats.Id
import cats.implicits._

Expand All @@ -31,23 +31,27 @@ class LruMapSpecification extends Properties("LruMap") {

property("Fill lru") = Prop.forAll(Gen.choose(1, 10000)) { size =>
val map: Id[LruMap[Id, Int, Int]] = CreateLruMap[Id, Int, Int].create(size)
val result = map.flatMap[Option[Int]](m => (1 to size).toList.traverse(n => m.put(n, n)).productR(m.get(0)))
val result = map.flatMap[Option[Int]](m =>
(1 to size).toList.traverse(n => m.put(n, n)).productR(m.get(0))
)
result.isEmpty
}

property("Last put") = Prop.forAll(Gen.listOf(Gen.identifier).suchThat(list => list.distinct == list)) { list =>
val map: Id[LruMap[Id, String, String]] = CreateLruMap[Id, String, String].create(list.length * 4)
val result = map
.flatMap[List[Option[String]]] { m =>
list.traverse[Id, Unit] { w => m.put(w, w) }.productR {
list.traverse[Id, Option[String]] { w => m.get(w) }
property("Last put") =
Prop.forAll(Gen.listOf(Gen.identifier).suchThat(list => list.distinct == list)) { list =>
val map: Id[LruMap[Id, String, String]] =
CreateLruMap[Id, String, String].create(list.length * 4)
val result = map
.flatMap[List[Option[String]]] { m =>
list.traverse[Id, Unit](w => m.put(w, w)).productR {
list.traverse[Id, Option[String]](w => m.get(w))
}
}
}

val res = result == list.map(x => Some(x))
if (!res) { println(s"list $list and result $result and len ${list.length}") }
res
}
val res = result == list.map(x => Some(x))
if (!res) { println(s"list $list and result $result and len ${list.length}") }
res
}

property("Evict lru") = Prop.forAll(Gen.choose(1, 1000)) { size =>
val map: Id[LruMap[Id, Int, Int]] = CreateLruMap[Id, Int, Int].create(size)
Expand Down

0 comments on commit a02687e

Please sign in to comment.