Skip to content

Commit

Permalink
Setup scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 committed Nov 13, 2020
1 parent 6a291cb commit 075ef40
Show file tree
Hide file tree
Showing 72 changed files with 985 additions and 846 deletions.
2 changes: 1 addition & 1 deletion .sbtrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
alias boot = ;reload ;project root ;iflast shell
alias boot = ;reload ;project kittens ;iflast shell
11 changes: 11 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version = "2.7.5"
align.preset = none
maxColumn = 120
includeNoParensInSelectChains = false
includeCurlyBraceInSelectChains = false
trailingCommas = "never"
rewrite.rules = [RedundantBraces, AvoidInfix, SortModifiers, PreferCurlyFors]
rewrite.redundantBraces.stringInterpolation = true
rewrite.redundantBraces.methodBodies = true
rewrite.redundantBraces.generalExpressions = true
rewriteTokens = { "⇒": "=>", "→": "->", "←": "<-" }
54 changes: 30 additions & 24 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ lazy val commonSettings = Seq(
Resolver.sonatypeRepo("snapshots")
),
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % catsVersion,
"org.typelevel" %%% "alleycats-core" % catsVersion,
"com.chuusai" %%% "shapeless" % shapelessVersion,
"org.typelevel" %%% "cats-testkit-scalatest" % testKitVersion % Test,
compilerPlugin("org.typelevel" %% "kind-projector" % "0.11.0" cross CrossVersion.full)
"org.typelevel" %%% "cats-core" % catsVersion,
"org.typelevel" %%% "alleycats-core" % catsVersion,
"com.chuusai" %%% "shapeless" % shapelessVersion,
"org.typelevel" %%% "cats-testkit-scalatest" % testKitVersion % Test,
compilerPlugin(("org.typelevel" %% "kind-projector" % "0.11.0").cross(CrossVersion.full))
),
scmInfo :=
Some(ScmInfo(
url("https://github.com/typelevel/kittens"),
"scm:git:[email protected]:typelevel/kittens.git"
)),
Some(
ScmInfo(
url("https://github.com/typelevel/kittens"),
"scm:git:[email protected]:typelevel/kittens.git"
)
),
testOptions += Tests.Argument("-oF"),
mimaPreviousArtifacts := Set(organization.value %% moduleName.value % "2.0.0")
) ++ crossVersionSharedSources
Expand All @@ -60,34 +62,38 @@ lazy val commonJvmSettings = Seq(

lazy val coreSettings = buildSettings ++ commonSettings ++ publishSettings ++ releaseSettings

lazy val root = project.in(file("."))
lazy val kittens = project
.in(file("."))
.aggregate(coreJS, coreJVM)
.dependsOn(coreJS, coreJVM)
.settings(coreSettings:_*)
.settings(coreSettings: _*)
.settings(noPublishSettings)

lazy val core = crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Pure)
lazy val core = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.settings(moduleName := "kittens")
.settings(coreSettings:_*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)

.settings(coreSettings: _*)
.jsSettings(commonJsSettings: _*)
.jvmSettings(commonJvmSettings: _*)

lazy val coreJVM = core.jvm
lazy val coreJS = core.js

addCommandAlias("validate", ";root;clean;test;mima;doc")
addCommandAlias("releaseAll", ";root;release")
addCommandAlias("js", ";project coreJS")
addCommandAlias("root", ";project kittens")
addCommandAlias("jvm", ";project coreJVM")
addCommandAlias("root", ";project root")
addCommandAlias("js", ";project coreJS")

addCommandAlias("validate", "all scalafmtCheckAll scalafmtSbtCheck test doc coreJVM/mimaReportBinaryIssues")
addCommandAlias("fmt", "all scalafmtSbt scalafmtAll")
addCommandAlias("fmtCheck", "all scalafmtSbtCheck scalafmtCheckAll")
addCommandAlias("mima", "coreJVM/mimaReportBinaryIssues")
addCommandAlias("releaseAll", ";root;release")

lazy val crossVersionSharedSources: Seq[Setting[_]] =
Seq(Compile, Test).map { sc =>
(unmanagedSourceDirectories in sc) ++= {
(unmanagedSourceDirectories in sc ).value.map {
dir:File => new File(dir.getPath + "_" + scalaBinaryVersion.value)
(unmanagedSourceDirectories in sc).value.map { dir: File =>
new File(dir.getPath + "_" + scalaBinaryVersion.value)
}
}
}
Expand All @@ -101,9 +107,9 @@ lazy val publishSettings = Seq(
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (version.value.trim.endsWith("SNAPSHOT"))
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"))
},
pomExtra :=
<developers>
Expand Down
61 changes: 30 additions & 31 deletions core/src/main/scala-2.12/cats/derived/semiauto.scala
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
package cats.derived

/**
* allows semi automatically derive each instance. The derivation might need help when
* there are fields with a type constructor that comes with instances, e.g.
* {{{
* scala> case class Bar(a: String)
* scala> case class Foo(bars: List[Bar])
* scala> import cats.instances.all._
*
* scala> cats.derived.semiauto.show[Foo].show(Foo(List(Bar("a"))))
* res1: String = Foo(bars = \$colon\$colon(head = Bar(a = a), tl\$access\$1 = Nil.type()))
* }}}
* Note that semi.show didn't respect the native `Show[List]` instance
*
* You could either derive a Bar instance first
* {{{
* scala> implicit val barShow = cats.derived.semi.show[Bar]
*
* scala> cats.derived.semiauto.show[Foo].show(Foo(List(Bar("a"))))
* res2: String = Foo(bars = List(Bar(a = a)))
* }}}
*
* Or you can take advantage of a controlled auto derivation
* {{{
* scala> implicit val fooShow: Show[Foo] = { |
* import cats.derived.auto.show._ |
* cats.derived.semiauto.show |
* }
* scala> Foo(List(Bar("a"))).show
* res3: String = Foo(bars = List(Bar(a = a)))
* }}}
*/
/** allows semi automatically derive each instance. The derivation might need help when
* there are fields with a type constructor that comes with instances, e.g.
* {{{
* scala> case class Bar(a: String)
* scala> case class Foo(bars: List[Bar])
* scala> import cats.instances.all._
*
* scala> cats.derived.semiauto.show[Foo].show(Foo(List(Bar("a"))))
* res1: String = Foo(bars = \$colon\$colon(head = Bar(a = a), tl\$access\$1 = Nil.type()))
* }}}
* Note that semi.show didn't respect the native `Show[List]` instance
*
* You could either derive a Bar instance first
* {{{
* scala> implicit val barShow = cats.derived.semi.show[Bar]
*
* scala> cats.derived.semiauto.show[Foo].show(Foo(List(Bar("a"))))
* res2: String = Foo(bars = List(Bar(a = a)))
* }}}
*
* Or you can take advantage of a controlled auto derivation
* {{{
* scala> implicit val fooShow: Show[Foo] = { |
* import cats.derived.auto.show._ |
* cats.derived.semiauto.show |
* }
* scala> Foo(List(Bar("a"))).show
* res3: String = Foo(bars = List(Bar(a = a)))
* }}}
*/
object semiauto extends SemiAutoInstances
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object VersionSpecific {
implicit def primary[A, B](implicit a: A): A OrElse B = new Primary(a)
}

private[util] abstract class OrElse0 {
abstract private[util] class OrElse0 {
implicit def secondary[A, B](implicit b: Lazy[B]): A OrElse B = new Secondary(b.value)
}
}
61 changes: 30 additions & 31 deletions core/src/main/scala-2.13/cats/derived/semiauto.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,36 @@ package derived
import alleycats.{ConsK, Empty, EmptyK, Pure}
import cats.kernel.{CommutativeMonoid, CommutativeSemigroup}

/**
* allows semi automatically derive each instance. The derivation might need help when
* there are fields with a type constructor that comes with instances, e.g.
* {{{
* scala> case class Bar(a: String)
* scala> case class Foo(bars: List[Bar])
* scala> import cats.instances.all._
*
* scala> cats.derived.semiauto.show[Foo].show(Foo(List(Bar("a"))))
* res1: String = Foo(bars = \$colon\$colon(head = Bar(a = a), tl\$access\$1 = Nil.type()))
* }}}
* Note that semi.show didn't respect the native `Show[List]` instance
*
* You could either derive a Bar instance first
* {{{
* scala> implicit val barShow = cats.derived.semi.show[Bar]
*
* scala> cats.derived.semiauto.show[Foo].show(Foo(List(Bar("a"))))
* res2: String = Foo(bars = List(Bar(a = a)))
* }}}
*
* Or you can take advantage of a controlled auto derivation
* {{{
* scala> implicit val fooShow: Show[Foo] = { |
* import cats.derived.auto.show._ |
* cats.derived.semiauto.show |
* }
* scala> Foo(List(Bar("a"))).show
* res3: String = Foo(bars = List(Bar(a = a)))
* }}}
*/
/** allows semi automatically derive each instance. The derivation might need help when
* there are fields with a type constructor that comes with instances, e.g.
* {{{
* scala> case class Bar(a: String)
* scala> case class Foo(bars: List[Bar])
* scala> import cats.instances.all._
*
* scala> cats.derived.semiauto.show[Foo].show(Foo(List(Bar("a"))))
* res1: String = Foo(bars = \$colon\$colon(head = Bar(a = a), tl\$access\$1 = Nil.type()))
* }}}
* Note that semi.show didn't respect the native `Show[List]` instance
*
* You could either derive a Bar instance first
* {{{
* scala> implicit val barShow = cats.derived.semi.show[Bar]
*
* scala> cats.derived.semiauto.show[Foo].show(Foo(List(Bar("a"))))
* res2: String = Foo(bars = List(Bar(a = a)))
* }}}
*
* Or you can take advantage of a controlled auto derivation
* {{{
* scala> implicit val fooShow: Show[Foo] = { |
* import cats.derived.auto.show._ |
* cats.derived.semiauto.show |
* }
* scala> Foo(List(Bar("a"))).show
* res3: String = Foo(bars = List(Bar(a = a)))
* }}}
*/
object semiauto {

def eq[A](implicit ev: MkEq[A]): Eq[A] = ev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object VersionSpecific {
implicit def primary[A, B](implicit a: A): A OrElse B = new Primary(a)
}

private[util] abstract class OrElse0 {
abstract private[util] class OrElse0 {
implicit def secondary[A, B](implicit b: => B): A OrElse B = new Secondary(b)
}
}
6 changes: 3 additions & 3 deletions core/src/main/scala/cats/derived/applicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object MkApplicative extends MkApplicativeDerivation {
def apply[F[_]](implicit F: MkApplicative[F]): MkApplicative[F] = F
}

private[derived] abstract class MkApplicativeDerivation extends MkApplicativeNested {
abstract private[derived] class MkApplicativeDerivation extends MkApplicativeNested {

implicit val mkApplicativeHNil: MkApplicative[Const[HNil]#λ] = new MkApplicative[Const[HNil]#λ] {
def pure[A](x: A) = HNil
Expand All @@ -51,7 +51,7 @@ private[derived] abstract class MkApplicativeDerivation extends MkApplicativeNes
}
}

private[derived] abstract class MkApplicativeNested extends MkApplicativeGeneric {
abstract private[derived] class MkApplicativeNested extends MkApplicativeGeneric {

implicit def mkApplicativeNested[F[_]](implicit F: Split1[F, ApplicativeOrMk, ApplicativeOrMk]): MkApplicative[F] =
new MkApplicative[F] {
Expand All @@ -69,7 +69,7 @@ private[derived] abstract class MkApplicativeNested extends MkApplicativeGeneric
}
}

private[derived] abstract class MkApplicativeGeneric {
abstract private[derived] class MkApplicativeGeneric {
protected type ApplicativeOrMk[F[_]] = Applicative[F] OrElse MkApplicative[F]

implicit def mkApplicativeHCons[F[_]](implicit F: IsHCons1[F, ApplicativeOrMk, MkApplicative]): MkApplicative[F] =
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/cats/derived/apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object MkApply extends MkApplyDerivation {
def apply[F[_]](implicit F: MkApply[F]): MkApply[F] = F
}

private[derived] abstract class MkApplyDerivation extends MkApplyNested {
abstract private[derived] class MkApplyDerivation extends MkApplyNested {

implicit val mkApplyHNil: MkApply[Const[HNil]#λ] = new MkApply[Const[HNil]#λ] {
def ap[A, B](ff: HNil)(fa: HNil) = ff
Expand All @@ -49,7 +49,7 @@ private[derived] abstract class MkApplyDerivation extends MkApplyNested {
}
}

private[derived] abstract class MkApplyNested extends MkApplyGeneric {
abstract private[derived] class MkApplyNested extends MkApplyGeneric {

implicit def mkApplyNested[F[_]](implicit F: Split1[F, ApplyOrMk, ApplyOrMk]): MkApply[F] =
new MkApply[F] {
Expand All @@ -64,7 +64,7 @@ private[derived] abstract class MkApplyNested extends MkApplyGeneric {
}
}

private[derived] abstract class MkApplyGeneric {
abstract private[derived] class MkApplyGeneric {
protected type ApplyOrMk[F[_]] = Apply[F] OrElse MkApply[F]

implicit def mkApplyHCons[F[_]](implicit F: IsHCons1[F, ApplyOrMk, MkApply]): MkApply[F] =
Expand Down
17 changes: 10 additions & 7 deletions core/src/main/scala/cats/derived/commutativeMonoid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@ object MkCommutativeMonoid extends MkCommutativeMonoidDerivation {
def apply[A](implicit ev: MkCommutativeMonoid[A]): MkCommutativeMonoid[A] = ev
}

private[derived] abstract class MkCommutativeMonoidDerivation {
abstract private[derived] class MkCommutativeMonoidDerivation {

implicit val mkCommutativeMonoidHNil: MkCommutativeMonoid[HNil] =
instance[HNil](HNil)((_, _) => HNil)

implicit def mkCommutativeMonoidHCons[H, T <: HList](
implicit H: CommutativeMonoid[H] OrElse MkCommutativeMonoid[H], T: MkCommutativeMonoid[T]
): MkCommutativeMonoid[H :: T] = instance(H.unify.empty :: T.empty) {
case (hx :: tx, hy :: ty) => H.unify.combine(hx, hy) :: T.combine(tx, ty)
implicit def mkCommutativeMonoidHCons[H, T <: HList](implicit
H: CommutativeMonoid[H] OrElse MkCommutativeMonoid[H],
T: MkCommutativeMonoid[T]
): MkCommutativeMonoid[H :: T] = instance(H.unify.empty :: T.empty) { case (hx :: tx, hy :: ty) =>
H.unify.combine(hx, hy) :: T.combine(tx, ty)
}


implicit def mkCommutativeMonoidGeneric[A, R](implicit A: Generic.Aux[A, R], R: Lazy[MkCommutativeMonoid[R]]): MkCommutativeMonoid[A] =
implicit def mkCommutativeMonoidGeneric[A, R](implicit
A: Generic.Aux[A, R],
R: Lazy[MkCommutativeMonoid[R]]
): MkCommutativeMonoid[A] =
new MkCommutativeMonoid[A] {
// Cache empty case classes.
lazy val empty = A.from(R.value.empty)
Expand Down
13 changes: 8 additions & 5 deletions core/src/main/scala/cats/derived/commutativeSemigroup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,26 @@ object MkCommutativeSemigroup extends MkCommutativeSemigroupDerivation {
def apply[A](implicit ev: MkCommutativeSemigroup[A]): MkCommutativeSemigroup[A] = ev
}

private[derived] abstract class MkCommutativeSemigroupDerivation {
abstract private[derived] class MkCommutativeSemigroupDerivation {

implicit val mkCommutativeSemigroupHNil: MkCommutativeSemigroup[HNil] =
instance((_, _) => HNil)

implicit def mkCommutativeSemigroupHCons[H, T <: HList](
implicit H: CommutativeSemigroup[H] OrElse MkCommutativeSemigroup[H], T: MkCommutativeSemigroup[T]
implicit def mkCommutativeSemigroupHCons[H, T <: HList](implicit
H: CommutativeSemigroup[H] OrElse MkCommutativeSemigroup[H],
T: MkCommutativeSemigroup[T]
): MkCommutativeSemigroup[H :: T] = instance { case (hx :: tx, hy :: ty) =>
H.unify.combine(hx, hy) :: T.combine(tx, ty)
}

implicit def mkCommutativeSemigroupGeneric[A, R](implicit A: Generic.Aux[A, R], R: Lazy[MkCommutativeSemigroup[R]]): MkCommutativeSemigroup[A] =
implicit def mkCommutativeSemigroupGeneric[A, R](implicit
A: Generic.Aux[A, R],
R: Lazy[MkCommutativeSemigroup[R]]
): MkCommutativeSemigroup[A] =
instance((x, y) => A.from(R.value.combine(A.to(x), A.to(y))))

private def instance[A](f: (A, A) => A): MkCommutativeSemigroup[A] =
new MkCommutativeSemigroup[A] {
def combine(x: A, y: A) = f(x, y)
}
}

Loading

0 comments on commit 075ef40

Please sign in to comment.