Skip to content

Commit

Permalink
Merge branch 'master' into more-utils-for-optiont
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/src/test/scala/cats/tests/OptionTSuite.scala
  • Loading branch information
ybasket committed Mar 12, 2020
2 parents 6fa9007 + 4351ea3 commit ff699db
Show file tree
Hide file tree
Showing 138 changed files with 779 additions and 516 deletions.
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
9 changes: 9 additions & 0 deletions PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ When fixing typos, improving documentation or minor build fix only
one sign-off is required (although for major edits waiting for two
may be preferable).

In some cases pull requests that don't target the master branch may be
merged with a single sign-off from a maintainer (as long as they
aren't also the author of the pull request). For example, backporting
changes from master to the `scala_2.11` branch generally shouldn't
require multiple reviews. If either the pull request author or a Cats
maintainer thinks that a specific change should receive multiple
approvals even though it doesn't target the master branch, their
request should be respected.

For serious emergencies or work on the build which can't easily be
reviewed or tested, pushing directly to master may be OK (but is
definitely not encouraged). In these cases it's best to comment in
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package alleycats
package tests
package alleycats.tests

import org.scalactic.anyvals.{PosInt, PosZDouble, PosZInt}
import org.scalatest.matchers.should.Matchers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package alleycats
package tests
package alleycats.tests

import org.scalactic.anyvals.{PosInt, PosZDouble, PosZInt}
import org.scalatest.matchers.should.Matchers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package alleycats
package tests
package alleycats.tests

import alleycats.std.MapInstances
import cats._
import cats.instances.AllInstances
import cats.syntax.{AllSyntax, EqOps}
import cats.instances.all._
import cats.tests.StrictCatsEquality
import org.scalatest.funsuite.AnyFunSuiteLike
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
import org.typelevel.discipline.scalatest.FunSuiteDiscipline
import org.scalacheck.{Arbitrary, Gen}
import org.scalacheck.Arbitrary.arbitrary
import org.scalatest.matchers.should.Matchers

import scala.util.{Failure, Success, Try}

/**
Expand All @@ -25,18 +22,12 @@ trait AlleycatsSuite
with ScalaCheckDrivenPropertyChecks
with FunSuiteDiscipline
with TestSettings
with AllInstances
with AllSyntax
with TestInstances
with StrictCatsEquality
with MapInstances {
implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
checkConfiguration

// disable Eq syntax (by making `catsSyntaxEq` not implicit), since it collides
// with scalactic's equality
override def catsSyntaxEq[A: Eq](a: A): EqOps[A] = new EqOps[A](a)

implicit def EqIterable[A: Eq]: Eq[Iterable[A]] = Eq.by(_.toList)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package alleycats
package tests
package alleycats.tests

import cats.{Eval, Foldable}
import alleycats.std.all._
import cats.{Eval, Foldable}
import cats.instances.all._
import cats.laws.discipline.FoldableTests

class IterableTests extends AlleycatsSuite {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package alleycats.tests

import cats.laws.discipline.arbitrary._
import cats.laws.discipline.{SerializableTests, TraverseFilterTests}
import cats.Traverse
import cats.instances.all._
import cats.laws.discipline.{SerializableTests, TraverseFilterTests}
import cats.laws.discipline.arbitrary._

class MapSuite extends AlleycatsSuite {
checkAll("Traverse[Map[Int, *]]", SerializableTests.serializable(Traverse[Map[Int, *]]))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package alleycats.tests

import alleycats.laws.discipline._
import alleycats.std.all._
import cats.Foldable
import cats.instances.all._
import cats.kernel.laws.discipline.SerializableTests
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.TraverseFilterTests

import alleycats.std.all._
import cats.laws.discipline.arbitrary._

class SetSuite extends AlleycatsSuite {
checkAll("FlatMapRec[Set]", FlatMapRecTests[Set].tailRecM[Int])
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Alternative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import simulacrum.typeclass
* {{{
* scala> import cats.implicits._
* scala> val l: List[Either[String, Int]] = List(Right(1), Left("error"))
* scala> Alternative[List].separate(l)
* scala> Alternative[List].separateFoldable(l)
* res0: (List[String], List[Int]) = (List(error),List(1))
* }}}
*/
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
2 changes: 2 additions & 0 deletions core/src/main/scala/cats/instances/either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
implicit def catsStdInstancesForEither[A]
: MonadError[Either[A, *], A] with Traverse[Either[A, *]] with Align[Either[A, *]] =
new MonadError[Either[A, *], A] with Traverse[Either[A, *]] with Align[Either[A, *]] {
override def unit: Either[A, Unit] = Either.unit

def pure[B](b: B): Either[A, B] = Right(b)

def flatMap[B, C](fa: Either[A, B])(f: B => Either[A, C]): Either[A, C] =
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
5 changes: 5 additions & 0 deletions core/src/main/scala/cats/syntax/either.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ final class EitherObjectOps(private val either: Either.type) extends AnyVal { //
case None => left[A, B](ifNone)
case Some(a) => right(a)
}

/** Cached value of `Right(())` to avoid allocations for a common case. */
def unit[A]: Either[A, Unit] = EitherUtil.unit
}

final class LeftOps[A, B](private val left: Left[A, B]) extends AnyVal {
Expand Down Expand Up @@ -456,4 +459,6 @@ private[cats] object EitherUtil {
right.asInstanceOf[Either[C, B]]
def rightCast[A, B, C](left: Left[A, B]): Either[A, C] =
left.asInstanceOf[Either[A, C]]

private[cats] val unit = Right(())
}
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)`
}
6 changes: 4 additions & 2 deletions free/src/test/scala/cats/free/CofreeSuite.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cats
package free
package cats.free

import cats.{~>, Comonad, Eval, Id, Reducible, Traverse}
import cats.data.{NonEmptyList, OptionT}
import cats.instances.all._
import cats.kernel.Eq
import cats.laws.discipline.{ComonadTests, ReducibleTests, SerializableTests, TraverseTests}
import cats.laws.discipline.SemigroupalTests.Isomorphisms
import cats.syntax.list._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cats
package free
package cats.free

import cats.{~>, Contravariant}
import cats.arrow.FunctionK
import cats.tests.CatsSuite
import cats.instances.all._
import cats.kernel.Eq
import cats.laws.discipline.{ContravariantTests, SerializableTests}

import cats.tests.CatsSuite
import org.scalacheck.{Arbitrary}

class ContravariantCoyonedaSuite extends CatsSuite {
Expand Down
9 changes: 5 additions & 4 deletions free/src/test/scala/cats/free/CoyonedaSuite.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cats
package free
package cats.free

import cats.tests.CatsSuite
import cats.Functor
import cats.arrow.FunctionK
import cats.instances.all._
import cats.kernel.Eq
import cats.laws.discipline.{FunctorTests, SerializableTests}

import cats.tests.CatsSuite
import org.scalacheck.Arbitrary

class CoyonedaSuite extends CatsSuite {
Expand Down
12 changes: 7 additions & 5 deletions free/src/test/scala/cats/free/FreeApplicativeSuite.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package cats
package free
package cats.free

import cats.tests.CatsSuite
import cats.{~>, Applicative, Apply, Id}
import cats.arrow.FunctionK
import cats.data.State
import cats.instances.all._
import cats.kernel.Eq
import cats.laws.discipline.{ApplicativeTests, SerializableTests}
import cats.laws.discipline.SemigroupalTests.Isomorphisms
import cats.data.State

import cats.syntax.apply._
import cats.tests.CatsSuite
import org.scalacheck.{Arbitrary, Gen}

class FreeApplicativeSuite extends CatsSuite {
Expand Down
12 changes: 8 additions & 4 deletions free/src/test/scala/cats/free/FreeInvariantMonoidalSuite.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package cats
package tests
package cats.free

import cats.{Id, InvariantMonoidal}
import cats.arrow.FunctionK
import cats.free.FreeInvariantMonoidal
import cats.kernel.Eq
import cats.instances.all._
import cats.laws.discipline.{InvariantMonoidalTests, MiniInt, SerializableTests}
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.SemigroupalTests.Isomorphisms
import org.scalacheck.{Arbitrary, Gen}
import cats.syntax.invariant._
import cats.syntax.semigroupal._
import cats.tests.BinCodecInvariantMonoidalSuite._
import cats.tests.CatsSuite
import org.scalacheck.{Arbitrary, Gen}

class FreeInvariantMonoidalSuite extends CatsSuite {
implicit def freeInvariantMonoidalArbitrary[F[_], A](implicit F: Arbitrary[F[A]],
Expand Down
10 changes: 6 additions & 4 deletions free/src/test/scala/cats/free/FreeSuite.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package cats
package free
package cats.free

import cats.{:<:, Foldable, Functor, Id, Monad, Traverse}
import cats.arrow.FunctionK
import cats.data.EitherK
import cats.instances.all._
import cats.kernel.Eq
import cats.laws.discipline.{DeferTests, FoldableTests, MonadTests, SerializableTests, TraverseTests}
import cats.laws.discipline.arbitrary.catsLawsArbitraryForFn0
import cats.laws.discipline.SemigroupalTests.Isomorphisms
import cats.syntax.apply._
import cats.tests.CatsSuite

import org.scalacheck.{Arbitrary, Cogen, Gen}
import Arbitrary.arbFunction1
import org.scalacheck.Arbitrary.arbFunction1

class FreeSuite extends CatsSuite {
import FreeSuite._
Expand Down
Loading

0 comments on commit ff699db

Please sign in to comment.