Skip to content

Commit

Permalink
Merge pull request #3232 from travisbrown/update/scalafmt-2.3.2
Browse files Browse the repository at this point in the history
Update Scalafmt to 2.3.2
  • Loading branch information
djspiewak authored Dec 31, 2019
2 parents 4f5f7ac + 66a7174 commit f44f251
Show file tree
Hide file tree
Showing 28 changed files with 202 additions and 258 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.1.0
version=2.3.2
align.openParenCallSite = true
align.openParenDefnSite = true
maxColumn = 120
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/scala-2.12/cats/instances/stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,12 @@ private[instances] trait StreamInstancesBinCompat0 {
override def flattenOption[A](fa: Stream[Option[A]]): Stream[A] = fa.flatten

def traverseFilter[G[_], A, B](fa: Stream[A])(f: (A) => G[Option[B]])(implicit G: Applicative[G]): G[Stream[B]] =
fa.foldRight(Eval.now(G.pure(Stream.empty[B])))(
(x, xse) => G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o))
)
fa.foldRight(Eval.now(G.pure(Stream.empty[B])))((x, xse) => G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o)))
.value

override def filterA[G[_], A](fa: Stream[A])(f: (A) => G[Boolean])(implicit G: Applicative[G]): G[Stream[A]] =
fa.foldRight(Eval.now(G.pure(Stream.empty[A])))(
(x, xse) => G.map2Eval(f(x), xse)((b, as) => if (b) x +: as else as)
fa.foldRight(Eval.now(G.pure(Stream.empty[A])))((x, xse) =>
G.map2Eval(f(x), xse)((b, as) => if (b) x +: as else as)
)
.value

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ sealed abstract private[data] class NonEmptyLazyListInstances extends NonEmptyLa
def monad: Monad[NonEmptyLazyList] = NonEmptyLazyList.catsDataInstancesForNonEmptyLazyList

def sequential: OneAnd[ZipLazyList, *] ~> NonEmptyLazyList =
λ[OneAnd[ZipLazyList, *] ~> NonEmptyLazyList](
znell => NonEmptyLazyList.fromLazyListPrepend(znell.head, znell.tail.value)
λ[OneAnd[ZipLazyList, *] ~> NonEmptyLazyList](znell =>
NonEmptyLazyList.fromLazyListPrepend(znell.head, znell.tail.value)
)

def parallel: NonEmptyLazyList ~> OneAnd[ZipLazyList, *] =
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/scala-2.13+/cats/instances/lazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,12 @@ trait LazyListInstances extends cats.kernel.instances.LazyListInstances {
def traverseFilter[G[_], A, B](
fa: LazyList[A]
)(f: (A) => G[Option[B]])(implicit G: Applicative[G]): G[LazyList[B]] =
fa.foldRight(Eval.now(G.pure(LazyList.empty[B])))(
(x, xse) => G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o))
)
fa.foldRight(Eval.now(G.pure(LazyList.empty[B])))((x, xse) => G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o)))
.value

override def filterA[G[_], A](fa: LazyList[A])(f: (A) => G[Boolean])(implicit G: Applicative[G]): G[LazyList[A]] =
fa.foldRight(Eval.now(G.pure(LazyList.empty[A])))(
(x, xse) => G.map2Eval(f(x), xse)((b, as) => if (b) x +: as else as)
fa.foldRight(Eval.now(G.pure(LazyList.empty[A])))((x, xse) =>
G.map2Eval(f(x), xse)((b, as) => if (b) x +: as else as)
)
.value

Expand Down
8 changes: 3 additions & 5 deletions core/src/main/scala-2.13+/cats/instances/stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,12 @@ private[instances] trait StreamInstancesBinCompat0 {
override def flattenOption[A](fa: Stream[Option[A]]): Stream[A] = fa.flatten

def traverseFilter[G[_], A, B](fa: Stream[A])(f: (A) => G[Option[B]])(implicit G: Applicative[G]): G[Stream[B]] =
fa.foldRight(Eval.now(G.pure(Stream.empty[B])))(
(x, xse) => G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o))
)
fa.foldRight(Eval.now(G.pure(Stream.empty[B])))((x, xse) => G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o)))
.value

override def filterA[G[_], A](fa: Stream[A])(f: (A) => G[Boolean])(implicit G: Applicative[G]): G[Stream[A]] =
fa.foldRight(Eval.now(G.pure(Stream.empty[A])))(
(x, xse) => G.map2Eval(f(x), xse)((b, as) => if (b) x +: as else as)
fa.foldRight(Eval.now(G.pure(Stream.empty[A])))((x, xse) =>
G.map2Eval(f(x), xse)((b, as) => if (b) x +: as else as)
)
.value

Expand Down
35 changes: 16 additions & 19 deletions core/src/main/scala/cats/Foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,11 @@ import Foldable.sentinel
*}}}
*/
def collectFoldSome[A, B](fa: F[A])(f: A => Option[B])(implicit B: Monoid[B]): B =
foldLeft(fa, B.empty)(
(acc, a) =>
f(a) match {
case Some(x) => B.combine(acc, x)
case None => acc
}
foldLeft(fa, B.empty)((acc, a) =>
f(a) match {
case Some(x) => B.combine(acc, x)
case None => acc
}
)

/**
Expand Down Expand Up @@ -699,12 +698,11 @@ import Foldable.sentinel
implicit val mb: Monoid[F[B]] = A.algebra[B]
implicit val mc: Monoid[F[C]] = A.algebra[C]

foldMap(fa)(
a =>
f(a) match {
case Right(c) => (A.empty[B], A.pure(c))
case Left(b) => (A.pure(b), A.empty[C])
}
foldMap(fa)(a =>
f(a) match {
case Right(c) => (A.empty[B], A.pure(c))
case Left(b) => (A.pure(b), A.empty[C])
}
)
}

Expand Down Expand Up @@ -806,8 +804,8 @@ import Foldable.sentinel
implicit val mb: Monoid[F[B]] = A.algebra[B]
implicit val mc: Monoid[F[C]] = A.algebra[C]

foldMap[A, (F[B], F[C])](fa)(
a => H.bifoldMap[B, C, (F[B], F[C])](f(a))(b => (A.pure(b), A.empty[C]), c => (A.empty[B], A.pure(c)))
foldMap[A, (F[B], F[C])](fa)(a =>
H.bifoldMap[B, C, (F[B], F[C])](f(a))(b => (A.pure(b), A.empty[C]), c => (A.empty[B], A.pure(c)))
)
}

Expand All @@ -832,11 +830,10 @@ import Foldable.sentinel
implicit val mb: Monoid[F[B]] = A.algebra[B]
implicit val mc: Monoid[F[C]] = A.algebra[C]

foldMapM[G, A, (F[B], F[C])](fa)(
a =>
M.map(f(a)) {
H.bifoldMap[B, C, (F[B], F[C])](_)(b => (A.pure(b), A.empty[C]), c => (A.empty[B], A.pure(c)))
}
foldMapM[G, A, (F[B], F[C])](fa)(a =>
M.map(f(a)) {
H.bifoldMap[B, C, (F[B], F[C])](_)(b => (A.pure(b), A.empty[C]), c => (A.empty[B], A.pure(c)))
}
)
}

Expand Down
34 changes: 16 additions & 18 deletions core/src/main/scala/cats/Monad.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ import simulacrum.typeclass
*/
def whileM[G[_], A](p: F[Boolean])(body: => F[A])(implicit G: Alternative[G]): F[G[A]] = {
val b = Eval.later(body)
tailRecM[G[A], G[A]](G.empty)(
xs =>
ifM(p)(
ifTrue = {
map(b.value) { bv =>
Left(G.combineK(xs, G.pure(bv)))
}
},
ifFalse = pure(Right(xs))
)
tailRecM[G[A], G[A]](G.empty)(xs =>
ifM(p)(
ifTrue = {
map(b.value) { bv =>
Left(G.combineK(xs, G.pure(bv)))
}
},
ifFalse = pure(Right(xs))
)
)
}

Expand All @@ -46,14 +45,13 @@ import simulacrum.typeclass
val continue: Either[Unit, Unit] = Left(())
val stop: F[Either[Unit, Unit]] = pure(Right(()))
val b = Eval.later(body)
tailRecM(())(
_ =>
ifM(p)(
ifTrue = {
map(b.value)(_ => continue)
},
ifFalse = stop
)
tailRecM(())(_ =>
ifM(p)(
ifTrue = {
map(b.value)(_ => continue)
},
ifFalse = stop
)
)
}

Expand Down
15 changes: 7 additions & 8 deletions core/src/main/scala/cats/Reducible.scala
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,13 @@ import simulacrum.{noop, typeclass}
import cats.syntax.either._

def g(a: A, eval: Eval[Ior[NonEmptyList[B], NonEmptyList[C]]]): Eval[Ior[NonEmptyList[B], NonEmptyList[C]]] =
eval.map(
ior =>
(f(a), ior) match {
case (Right(c), Ior.Left(_)) => ior.putRight(NonEmptyList.one(c))
case (Right(c), _) => ior.map(c :: _)
case (Left(b), Ior.Right(r)) => Ior.bothNel(b, r)
case (Left(b), _) => ior.leftMap(b :: _)
}
eval.map(ior =>
(f(a), ior) match {
case (Right(c), Ior.Left(_)) => ior.putRight(NonEmptyList.one(c))
case (Right(c), _) => ior.map(c :: _)
case (Left(b), Ior.Right(r)) => Ior.bothNel(b, r)
case (Left(b), _) => ior.leftMap(b :: _)
}
)

reduceRightTo(fa)(a => f(a).bimap(NonEmptyList.one, NonEmptyList.one).toIor)(g).value
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/scala/cats/data/Chain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -812,15 +812,13 @@ sealed abstract private[data] class ChainInstances extends ChainInstances1 {

def traverseFilter[G[_], A, B](fa: Chain[A])(f: A => G[Option[B]])(implicit G: Applicative[G]): G[Chain[B]] =
traverse
.foldRight(fa, Eval.now(G.pure(Chain.empty[B])))(
(x, xse) => G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o))
)
.foldRight(fa, Eval.now(G.pure(Chain.empty[B])))((x, xse) => G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o)))
.value

override def filterA[G[_], A](fa: Chain[A])(f: A => G[Boolean])(implicit G: Applicative[G]): G[Chain[A]] =
traverse
.foldRight(fa, Eval.now(G.pure(Chain.empty[A])))(
(x, xse) => G.map2Eval(f(x), xse)((b, chain) => if (b) x +: chain else chain)
.foldRight(fa, Eval.now(G.pure(Chain.empty[A])))((x, xse) =>
G.map2Eval(f(x), xse)((b, chain) => if (b) x +: chain else chain)
)
.value

Expand Down
13 changes: 6 additions & 7 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -946,13 +946,12 @@ private[data] trait EitherTMonad[F[_], L] extends Monad[EitherT[F, L, *]] with E
def flatMap[A, B](fa: EitherT[F, L, A])(f: A => EitherT[F, L, B]): EitherT[F, L, B] = fa.flatMap(f)
def tailRecM[A, B](a: A)(f: A => EitherT[F, L, Either[A, B]]): EitherT[F, L, B] =
EitherT(
F.tailRecM(a)(
a0 =>
F.map(f(a0).value) {
case Left(l) => Right(Left(l))
case Right(Left(a1)) => Left(a1)
case Right(Right(b)) => Right(Right(b))
}
F.tailRecM(a)(a0 =>
F.map(f(a0).value) {
case Left(l) => Right(Left(l))
case Right(Left(a1)) => Left(a1)
case Right(Right(b)) => Right(Right(b))
}
)
)
}
Expand Down
34 changes: 14 additions & 20 deletions core/src/main/scala/cats/data/IndexedStateT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,10 @@ final class IndexedStateT[F[_], SA, SB, A](val runF: F[SA => F[(SB, A)]]) extend
* }}}
*/
def transformS[R](f: R => SA, g: (R, SB) => R)(implicit F: Functor[F]): IndexedStateT[F, R, R, A] =
StateT.applyF(F.map(runF) {
sfsa =>
{ (r: R) =>
val sa = f(r)
val fsba = sfsa(sa)
F.map(fsba) { case (sb, a) => (g(r, sb), a) }
}
StateT.applyF(F.map(runF) { sfsa => (r: R) =>
val sa = f(r)
val fsba = sfsa(sa)
F.map(fsba) { case (sb, a) => (g(r, sb), a) }
})

/**
Expand Down Expand Up @@ -435,11 +432,10 @@ sealed abstract private[data] class IndexedStateTMonad[F[_], S]
fa.flatMap(f)

def tailRecM[A, B](a: A)(f: A => IndexedStateT[F, S, S, Either[A, B]]): IndexedStateT[F, S, S, B] =
IndexedStateT[F, S, S, B](
s =>
F.tailRecM[(S, A), (S, B)]((s, a)) {
case (s, a) => F.map(f(a).run(s)) { case (s, ab) => ab.bimap((s, _), (s, _)) }
}
IndexedStateT[F, S, S, B](s =>
F.tailRecM[(S, A), (S, B)]((s, a)) {
case (s, a) => F.map(f(a).run(s)) { case (s, ab) => ab.bimap((s, _), (s, _)) }
}
)
}

Expand Down Expand Up @@ -470,14 +466,12 @@ sealed abstract private[data] class IndexedStateTContravariantMonoidal[F[_], S]
def contramap2[A, B, C](fb: IndexedStateT[F, S, S, B],
fc: IndexedStateT[F, S, S, C])(f: A => (B, C)): IndexedStateT[F, S, S, A] =
IndexedStateT.applyF(
G.pure(
(s: S) =>
ContravariantMonoidal.contramap2(G.map(fb.runF)(_.apply(s)), G.map(fc.runF)(_.apply(s)))(
(tup: (S, A)) =>
f(tup._2) match {
case (b, c) => (G.pure((tup._1, b)), G.pure((tup._1, c)))
}
)(G, F)
G.pure((s: S) =>
ContravariantMonoidal.contramap2(G.map(fb.runF)(_.apply(s)), G.map(fc.runF)(_.apply(s)))((tup: (S, A)) =>
f(tup._2) match {
case (b, c) => (G.pure((tup._1, b)), G.pure((tup._1, c)))
}
)(G, F)
)
)
}
Expand Down
11 changes: 5 additions & 6 deletions core/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,11 @@ private[data] trait KleisliArrowChoice[F[_]]
Kleisli { case (a, c) => F.flatMap(f.run(a))(b => F.map(g.run(c))(d => (b, d))) }

def choose[A, B, C, D](f: Kleisli[F, A, C])(g: Kleisli[F, B, D]): Kleisli[F, Either[A, B], Either[C, D]] =
Kleisli(
(fe: Either[A, B]) =>
fe match {
case Left(a) => F.map(f(a))(Left.apply _)
case Right(b) => F.map(g(b))(Right.apply _)
}
Kleisli((fe: Either[A, B]) =>
fe match {
case Left(a) => F.map(f(a))(Left.apply _)
case Right(b) => F.map(g(b))(Right.apply _)
}
)
}

Expand Down
15 changes: 7 additions & 8 deletions core/src/main/scala/cats/data/NonEmptyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,13 @@ sealed abstract private[data] class NonEmptyListInstances extends NonEmptyListIn
val reversed = fa.reverse
val lastIor = f(reversed.head).bimap(NonEmptyList.one, NonEmptyList.one).toIor

reversed.tail.foldLeft(lastIor)(
(ior, a) =>
(f(a), ior) match {
case (Right(c), Ior.Left(_)) => ior.putRight(NonEmptyList.one(c))
case (Right(c), _) => ior.map(c :: _)
case (Left(b), Ior.Right(r)) => Ior.bothNel(b, r)
case (Left(b), _) => ior.leftMap(b :: _)
}
reversed.tail.foldLeft(lastIor)((ior, a) =>
(f(a), ior) match {
case (Right(c), Ior.Left(_)) => ior.putRight(NonEmptyList.one(c))
case (Right(c), _) => ior.map(c :: _)
case (Left(b), Ior.Right(r)) => Ior.bothNel(b, r)
case (Left(b), _) => ior.leftMap(b :: _)
}
)

}
Expand Down
15 changes: 7 additions & 8 deletions core/src/main/scala/cats/data/NonEmptyVector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,13 @@ sealed abstract private[data] class NonEmptyVectorInstances {
import cats.syntax.either._
import cats.syntax.reducible._

reduceLeftTo(fa)(a => f(a).bimap(NonEmptyVector.one, NonEmptyVector.one).toIor)(
(ior, a) =>
(f(a), ior) match {
case (Right(c), Ior.Left(_)) => ior.putRight(NonEmptyVector.one(c))
case (Right(c), _) => ior.map(_ :+ c)
case (Left(b), Ior.Right(_)) => ior.putLeft(NonEmptyVector.one(b))
case (Left(b), _) => ior.leftMap(_ :+ b)
}
reduceLeftTo(fa)(a => f(a).bimap(NonEmptyVector.one, NonEmptyVector.one).toIor)((ior, a) =>
(f(a), ior) match {
case (Right(c), Ior.Left(_)) => ior.putRight(NonEmptyVector.one(c))
case (Right(c), _) => ior.map(_ :+ c)
case (Left(b), Ior.Right(_)) => ior.putLeft(NonEmptyVector.one(b))
case (Left(b), _) => ior.leftMap(_ :+ b)
}
).bimap(_.toNonEmptyList, _.toNonEmptyList)

}
Expand Down
20 changes: 9 additions & 11 deletions core/src/main/scala/cats/data/OptionT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,10 @@ private[data] trait OptionTMonad[F[_]] extends Monad[OptionT[F, *]] {

def tailRecM[A, B](a: A)(f: A => OptionT[F, Either[A, B]]): OptionT[F, B] =
OptionT(
F.tailRecM(a)(
a0 =>
F.map(f(a0).value)(
_.fold(Either.right[A, Option[B]](None))(_.map(b => Some(b): Option[B]))
)
F.tailRecM(a)(a0 =>
F.map(f(a0).value)(
_.fold(Either.right[A, Option[B]](None))(_.map(b => Some(b): Option[B]))
)
)
)
}
Expand Down Expand Up @@ -423,12 +422,11 @@ private trait OptionTContravariantMonoidal[F[_]] extends ContravariantMonoidal[O

override def product[A, B](fa: OptionT[F, A], fb: OptionT[F, B]): OptionT[F, (A, B)] =
OptionT(
F.contramap(F.product(fa.value, fb.value))(
(t: Option[(A, B)]) =>
t match {
case Some((x, y)) => (Some(x), Some(y))
case None => (None, None)
}
F.contramap(F.product(fa.value, fb.value))((t: Option[(A, B)]) =>
t match {
case Some((x, y)) => (Some(x), Some(y))
case None => (None, None)
}
)
)
}
Expand Down
Loading

0 comments on commit f44f251

Please sign in to comment.