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

Update Scalafmt to 2.4.2 #3337

Merged
merged 3 commits into from
Mar 1, 2020
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
3 changes: 2 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.3.2
version=2.4.2
align.openParenCallSite = true
align.openParenDefnSite = true
maxColumn = 120
Expand All @@ -7,3 +7,4 @@ assumeStandardLibraryStripMargin = true
danglingParentheses = true
rewrite.rules = [AvoidInfix, SortImports, RedundantBraces, RedundantParens, SortModifiers]
docstrings = JavaDoc
newlines.afterCurlyLambda = preserve
8 changes: 4 additions & 4 deletions alleycats-core/src/main/scala/alleycats/std/map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ trait MapInstances {
val gba: Eval[G[Map[K, B]]] = Always(G.pure(Map.empty))
val gbb = Foldable
.iterateRight(fa, gba) { (kv, lbuf) =>
G.map2Eval(f(kv._2), lbuf)({ (b, buf) =>
G.map2Eval(f(kv._2), lbuf) { (b, buf) =>
buf + (kv._1 -> b)
})
}
}
.value
G.map(gbb)(_.toMap)
Expand Down Expand Up @@ -67,9 +67,9 @@ trait MapInstances {
val gba: Eval[G[Map[K, B]]] = Always(G.pure(Map.empty))
Foldable
.iterateRight(fa, gba) { (kv, lbuf) =>
G.map2Eval(f(kv._2), lbuf)({ (ob, buf) =>
G.map2Eval(f(kv._2), lbuf) { (ob, buf) =>
ob.fold(buf)(b => buf + (kv._1 -> b))
})
}
}
.value
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/Cokleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ private[data] class CokleisliMonad[F[_], A] extends Monad[Cokleisli[F, A, *]] {
fa.map(f)

def tailRecM[B, C](b: B)(fn: B => Cokleisli[F, A, Either[B, C]]): Cokleisli[F, A, C] =
Cokleisli({ (fa: F[A]) =>
Cokleisli { (fa: F[A]) =>
@tailrec
def loop(c: Cokleisli[F, A, Either[B, C]]): C = c.run(fa) match {
case Right(c) => c
case Left(bb) => loop(fn(bb))
}
loop(fn(b))
})
}

}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/Func.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ sealed abstract class AppFunc[F[_], A, B] extends Func[F, A, B] { self =>

def compose[G[_], C](g: AppFunc[G, C, A]): AppFunc[Nested[G, F, *], C, B] = {
implicit val gfApplicative: Applicative[Nested[G, F, *]] = Nested.catsDataApplicativeForNested[G, F](g.F, F)
Func.appFunc[Nested[G, F, *], C, B]({ (c: C) =>
Func.appFunc[Nested[G, F, *], C, B] { (c: C) =>
Nested(g.F.map(g.run(c))(self.run))
})
}
}

def andThen[G[_], C](g: AppFunc[G, B, C]): AppFunc[Nested[F, G, *], A, C] =
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,9 @@ private[data] trait KleisliFlatMap[F[_], A] extends FlatMap[Kleisli[F, A, *]] wi
fa.flatMap(f)

def tailRecM[B, C](b: B)(f: B => Kleisli[F, A, Either[B, C]]): Kleisli[F, A, C] =
Kleisli[F, A, C]({ a =>
F.tailRecM(b) { f(_).run(a) }
})
Kleisli[F, A, C] { a =>
F.tailRecM(b)(f(_).run(a))
}
}

private[data] trait KleisliApplicative[F[_], A] extends Applicative[Kleisli[F, A, *]] with KleisliApply[F, A] {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/WriterT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ final case class WriterT[F[_], L, V](run: F[(L, V)]) {
* }}}
*/
def mapBoth[M, U](f: (L, V) => (M, U))(implicit functorF: Functor[F]): WriterT[F, M, U] =
WriterT { functorF.map(run)(f.tupled) }
WriterT(functorF.map(run)(f.tupled))

/**
* Example:
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/instances/map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ trait MapInstances extends cats.kernel.instances.MapInstances {
val gba: Eval[G[Map[K, B]]] = Always(G.pure(Map.empty))
val gbb = Foldable
.iterateRight(fa, gba) { (kv, lbuf) =>
G.map2Eval(f(kv._2), lbuf)({ (b, buf) =>
G.map2Eval(f(kv._2), lbuf) { (b, buf) =>
buf + (kv._1 -> b)
})
}
}
.value
G.map(gbb)(_.toMap)
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/cats/instances/sortedMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ trait SortedMapInstances extends SortedMapInstances2 {
val gba: Eval[G[SortedMap[K, B]]] = Always(G.pure(SortedMap.empty(Order[K].toOrdering)))
Foldable
.iterateRight(fa, gba) { (kv, lbuf) =>
G.map2Eval(f(kv._2), lbuf)({ (b, buf) =>
G.map2Eval(f(kv._2), lbuf) { (b, buf) =>
buf + (kv._1 -> b)
})
}
}
.value
}
Expand Down Expand Up @@ -186,9 +186,9 @@ private[instances] trait SortedMapInstancesBinCompat0 {
val gba: Eval[G[SortedMap[K, B]]] = Always(G.pure(SortedMap.empty))
Foldable
.iterateRight(fa, gba) { (kv, lbuf) =>
G.map2Eval(f(kv._2), lbuf)({ (ob, buf) =>
G.map2Eval(f(kv._2), lbuf) { (ob, buf) =>
ob.fold(buf)(b => buf + (kv._1 -> b))
})
}
}
.value
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/cats/syntax/monadError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ final class MonadErrorOps[F[_], E, A](private val fa: F[A]) extends AnyVal {

final class MonadErrorRethrowOps[F[_], E, A](private val fea: F[Either[E, A]]) extends AnyVal {
def rethrow(implicit F: MonadError[F, _ >: E]): F[A] =
F.flatMap(fea)(_.fold(F.raiseError, F.pure)) // dup from the type class impl, due to https://github.com/scala/bug/issues/11562. Once fixed should be able to replace with `F.rethrow(fea)`
F.flatMap(fea)(
_.fold(F.raiseError, F.pure)
) // dup from the type class impl, due to https://github.com/scala/bug/issues/11562. Once fixed should be able to replace with `F.rethrow(fea)`
}
20 changes: 10 additions & 10 deletions project/Boilerplate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Boilerplate {
def block(args: Any*): String = {
val interpolated = sc.standardInterpolator(treatEscapes, args)
val rawLines = interpolated.split('\n')
val trimmedLines = rawLines.map { _.dropWhile(_.isWhitespace) }
val trimmedLines = rawLines.map(_.dropWhile(_.isWhitespace))
trimmedLines.mkString("\n")
}
}
Expand Down Expand Up @@ -65,8 +65,8 @@ object Boilerplate {
acc.map(_.tail)
else {
val pre = contents.head.takeWhile(_.startsWith("|"))
val instances = contents.flatMap { _.dropWhile(_.startsWith("|")).takeWhile(_.startsWith("-")) }
val next = contents.map { _.dropWhile(_.startsWith("|")).dropWhile(_.startsWith("-")) }
val instances = contents.flatMap(_.dropWhile(_.startsWith("|")).takeWhile(_.startsWith("-")))
val next = contents.map(_.dropWhile(_.startsWith("|")).dropWhile(_.startsWith("-")))
expandInstances(next, acc ++ pre ++ instances)
}

Expand Down Expand Up @@ -174,14 +174,14 @@ object Boilerplate {
val tpes = synTypes.map { tpe =>
s"F[$tpe]"
}
val fargs = (0 until arity).map { "f" + _ }
val fargs = (0 until arity).map("f" + _)
val fparams = (fargs.zip(tpes)).map { case (v, t) => s"$v:$t" }.mkString(", ")

val a = arity / 2
val b = arity - a

val fArgsA = (0 until a).map { "f" + _ }.mkString(",")
val fArgsB = (a until arity).map { "f" + _ }.mkString(",")
val fArgsA = (0 until a).map("f" + _).mkString(",")
val fArgsB = (a until arity).map("f" + _).mkString(",")
val argsA = (0 until a)
.map { n =>
"a" + n + ":A" + n
Expand All @@ -198,7 +198,7 @@ object Boilerplate {
} else {
s"ap$n"
}
def allArgs = (0 until arity).map { "a" + _ }.mkString(",")
def allArgs = (0 until arity).map("a" + _).mkString(",")

val apply =
block"""
Expand Down Expand Up @@ -253,7 +253,7 @@ object Boilerplate {
val tpes = synTypes.map { tpe =>
s"M[$tpe]"
}
val fargs = (0 until arity).map { "m" + _ }
val fargs = (0 until arity).map("m" + _)
val fparams = (fargs.zip(tpes)).map { case (v, t) => s"$v:$t" }.mkString(", ")
val fargsS = fargs.mkString(", ")
val nestedExpansion = ParallelNestedExpansions(arity)
Expand Down Expand Up @@ -286,7 +286,7 @@ object Boilerplate {
val tpes = synTypes.map { tpe =>
s"M[$tpe]"
}
val fargs = (0 until arity).map { "m" + _ }
val fargs = (0 until arity).map("m" + _)
val fparams = (fargs.zip(tpes)).map { case (v, t) => s"$v:$t" }.mkString(", ")
val fargsS = fargs.mkString(", ")
val nestedExpansion = ParallelNestedExpansions(arity)
Expand Down Expand Up @@ -319,7 +319,7 @@ object Boilerplate {
val tpes = synTypes.map { tpe =>
s"F[$tpe]"
}
val fargs = (0 until arity).map { "f" + _ }
val fargs = (0 until arity).map("f" + _)
val fparams = (fargs.zip(tpes)).map { case (v, t) => s"$v:$t" }.mkString(", ")
val fargsS = fargs.mkString(", ")

Expand Down
4 changes: 2 additions & 2 deletions tests/src/test/scala/cats/tests/AndThenSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ class AndThenSuite extends CatsSuite with Checkers {

test("andThen is stack safe") {
val count = if (Platform.isJvm) 500000 else 1000
val fs = (0 until count).map(_ => { (i: Int) => i + 1 })
val fs = (0 until count).map(_ => (i: Int) => i + 1)
val result = fs.foldLeft(AndThen((x: Int) => x))(_.andThen(_))(42)

result shouldEqual (count + 42)
}

test("compose is stack safe") {
val count = if (Platform.isJvm) 500000 else 1000
val fs = (0 until count).map(_ => { (i: Int) => i + 1 })
val fs = (0 until count).map(_ => (i: Int) => i + 1)
val result = fs.foldLeft(AndThen((x: Int) => x))(_.compose(_))(42)

result shouldEqual (count + 42)
Expand Down
6 changes: 3 additions & 3 deletions tests/src/test/scala/cats/tests/EitherSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ class EitherSuite extends CatsSuite {

test("catchOnly lets non-matching exceptions escape") {
val _ = intercept[NumberFormatException] {
Either.catchOnly[IndexOutOfBoundsException] { "foo".toInt }
Either.catchOnly[IndexOutOfBoundsException]("foo".toInt)
}
}

test("catchNonFatal catches non-fatal exceptions") {
assert(Either.catchNonFatal { "foo".toInt }.isLeft)
assert(Either.catchNonFatal { throw new Throwable("blargh") }.isLeft)
assert(Either.catchNonFatal("foo".toInt).isLeft)
assert(Either.catchNonFatal(throw new Throwable("blargh")).isLeft)
}

test("fromTry is left for failed Try") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,21 @@ class ReaderWriterStateTSuite extends CatsSuite {
}

test("flatMap and flatMapF+tell are consistent") {
forAll { (rwst: ReaderWriterStateT[Option, String, String, String, Int], f: Int => Option[Int], initial: String, context: String, log: String) =>
val flatMap = rwst.flatMap { a =>
ReaderWriterStateT { (e, s) =>
f(a).map((log, s, _))
forAll {
(rwst: ReaderWriterStateT[Option, String, String, String, Int],
f: Int => Option[Int],
initial: String,
context: String,
log: String) =>
val flatMap = rwst.flatMap { a =>
ReaderWriterStateT { (e, s) =>
f(a).map((log, s, _))
}
}
}

val flatMapF = rwst.flatMapF(f).tell(log)
val flatMapF = rwst.flatMapF(f).tell(log)

flatMap.run(context, initial) should ===(flatMapF.run(context, initial))
flatMap.run(context, initial) should ===(flatMapF.run(context, initial))
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/src/test/scala/cats/tests/RegressionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class RegressionSuite extends CatsSuite with ScalaVersionSpecificRegressionSuite
// not stack safe, very minimal, not for actual use
case class State[S, A](run: S => (A, S)) { self =>
def map[B](f: A => B): State[S, B] =
State({ s =>
State { s =>
val (a, s2) = self.run(s); (f(a), s2)
})
}
def flatMap[B](f: A => State[S, B]): State[S, B] =
State({ s =>
State { s =>
val (a, s2) = self.run(s); f(a).run(s2)
})
}
}

object State {
Expand Down
8 changes: 4 additions & 4 deletions tests/src/test/scala/cats/tests/ValidatedSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ class ValidatedSuite extends CatsSuite {
}

test("catchOnly catches matching exceptions") {
assert(Validated.catchOnly[NumberFormatException] { "foo".toInt }.isInstanceOf[Invalid[NumberFormatException]])
assert(Validated.catchOnly[NumberFormatException]("foo".toInt).isInstanceOf[Invalid[NumberFormatException]])
}

test("catchOnly lets non-matching exceptions escape") {
val _ = intercept[NumberFormatException] {
Validated.catchOnly[IndexOutOfBoundsException] { "foo".toInt }
Validated.catchOnly[IndexOutOfBoundsException]("foo".toInt)
}
}

test("catchNonFatal catches non-fatal exceptions") {
assert(Validated.catchNonFatal { "foo".toInt }.isInvalid)
assert(Validated.catchNonFatal { throw new Throwable("blargh") }.isInvalid)
assert(Validated.catchNonFatal("foo".toInt).isInvalid)
assert(Validated.catchNonFatal(throw new Throwable("blargh")).isInvalid)
}

test("fromTry is invalid for failed try") {
Expand Down