From a7e9673c78dc2534f711a210556e0be2de642bb0 Mon Sep 17 00:00:00 2001 From: Greg Pfeil Date: Wed, 15 Mar 2017 20:24:19 -0600 Subject: [PATCH 1/2] Port to Cats. --- .../monocle/bench/MonocleLensBench.scala | 2 +- .../monocle/bench/MonocleMacroLensBench.scala | 2 +- .../monocle/bench/MonocleTraversalBench.scala | 4 +- build.sbt | 41 ++-- core/shared/src/main/scala/monocle/Fold.scala | 36 ++-- .../src/main/scala/monocle/Getter.scala | 18 +- core/shared/src/main/scala/monocle/Iso.scala | 31 +-- core/shared/src/main/scala/monocle/Lens.scala | 31 +-- .../src/main/scala/monocle/Optional.scala | 15 +- .../shared/src/main/scala/monocle/Prism.scala | 16 +- .../src/main/scala/monocle/Setter.scala | 18 +- .../src/main/scala/monocle/Traversal.scala | 57 ++--- .../src/main/scala/monocle/function/At.scala | 16 +- .../main/scala/monocle/function/Cons.scala | 16 +- .../main/scala/monocle/function/Cons1.scala | 15 +- .../main/scala/monocle/function/Each.scala | 31 +-- .../main/scala/monocle/function/Empty.scala | 24 +-- .../main/scala/monocle/function/Field1.scala | 6 +- .../scala/monocle/function/FilterIndex.scala | 33 +-- .../main/scala/monocle/function/Index.scala | 20 +- .../main/scala/monocle/function/Plated.scala | 37 +--- .../scala/monocle/function/Possible.scala | 12 +- .../main/scala/monocle/function/Reverse.scala | 14 +- .../main/scala/monocle/function/Snoc.scala | 22 +- .../main/scala/monocle/function/Snoc1.scala | 9 +- .../main/scala/monocle/function/Wrapped.scala | 28 +-- .../main/scala/monocle/internal/Bounded.scala | 4 +- .../src/main/scala/monocle/law/IsoLaws.scala | 6 +- .../src/main/scala/monocle/law/LensLaws.scala | 6 +- .../main/scala/monocle/law/OptionalLaws.scala | 14 +- .../main/scala/monocle/law/PrismLaws.scala | 14 +- .../src/main/scala/monocle/std/All.scala | 8 +- .../src/main/scala/monocle/std/Byte.scala | 2 +- .../src/main/scala/monocle/std/Char.scala | 2 +- .../src/main/scala/monocle/std/Cofree.scala | 29 +-- .../main/scala/monocle/std/Disjunction.scala | 33 --- .../src/main/scala/monocle/std/Either.scala | 10 +- .../src/main/scala/monocle/std/Either3.scala | 40 ---- .../src/main/scala/monocle/std/IList.scala | 15 -- .../src/main/scala/monocle/std/IMap.scala | 5 - .../src/main/scala/monocle/std/Int.scala | 2 +- .../src/main/scala/monocle/std/Long.scala | 2 +- .../src/main/scala/monocle/std/Maybe.scala | 25 --- .../main/scala/monocle/std/NonEmptyList.scala | 13 +- .../src/main/scala/monocle/std/Option.scala | 4 +- .../src/main/scala/monocle/std/String.scala | 8 +- .../src/main/scala/monocle/std/These.scala | 11 +- .../src/main/scala/monocle/std/Tree.scala | 51 ----- .../src/main/scala/monocle/std/Try.scala | 2 +- .../main/scala/monocle/std/Validation.scala | 17 +- .../src/main/scala/monocle/syntax/All.scala | 2 +- .../src/main/scala/monocle/syntax/Apply.scala | 2 +- .../main/scala/monocle/syntax/Traversal.scala | 112 ---------- docs/src/main/tut/modules.md | 4 +- docs/src/main/tut/optics/lens.md | 6 +- docs/src/main/tut/optics/traversal.md | 12 +- .../src/test/scala/monocle/JsonExample.scala | 10 +- .../scala/monocle/function/AtExample.scala | 3 +- .../scala/monocle/function/EachExample.scala | 10 +- .../scala/monocle/function/EmptyExample.scala | 3 - .../monocle/function/FilterIndexExample.scala | 3 +- .../scala/monocle/function/HeadExample.scala | 2 +- .../monocle/function/HeadOptionExample.scala | 2 +- .../scala/monocle/function/IndexExample.scala | 4 +- .../monocle/function/InitOptionExample.scala | 2 +- .../monocle/function/LastOptionExample.scala | 2 +- .../monocle/function/ReverseExample.scala | 6 - .../scala/monocle/function/TailExample.scala | 4 +- .../monocle/function/TailOptionExample.scala | 2 +- .../monocle/function/WrappedExample.scala | 7 +- .../scala/monocle/state/StateExample.scala | 196 +----------------- .../test/scala/monocle/std/TheseExample.scala | 11 +- .../test/scala/monocle/std/TreeExample.scala | 53 ----- .../scala/monocle/std/ValidationExample.scala | 12 +- .../syntax/SymbolicSyntaxExample.scala | 4 +- .../src/test/scala/other/ImportExample.scala | 2 +- .../main/scala/monocle/generic/Product.scala | 6 +- .../monocle/law/discipline/IsoTests.scala | 4 +- .../monocle/law/discipline/LensTests.scala | 2 +- .../law/discipline/OptionalTests.scala | 4 +- .../monocle/law/discipline/PrismTests.scala | 4 +- .../monocle/law/discipline/SetterTests.scala | 2 +- .../law/discipline/TraversalTests.scala | 6 +- .../law/discipline/function/AtTests.scala | 4 +- .../law/discipline/function/Cons1Tests.scala | 6 +- .../law/discipline/function/ConsTests.scala | 6 +- .../law/discipline/function/EachTests.scala | 4 +- .../law/discipline/function/EmptyTests.scala | 6 +- .../function/FilterIndexTests.scala | 4 +- .../law/discipline/function/IndexTests.scala | 4 +- .../discipline/function/PossibleTests.scala | 2 +- .../discipline/function/ReverseTests.scala | 4 +- .../law/discipline/function/Snoc1Tests.scala | 6 +- .../law/discipline/function/SnocTests.scala | 6 +- .../monocle/law/discipline/package.scala | 4 +- .../main/scala/monocle/macros/GenPrism.scala | 2 +- .../scala/monocle/macros/internal/Macro.scala | 2 +- project/plugins.sbt | 2 +- .../src/main/scala/monocle/state/All.scala | 1 - .../monocle/state/ReaderGetterSyntax.scala | 2 +- .../monocle/state/StateGetterSyntax.scala | 2 +- .../scala/monocle/state/StateLensSyntax.scala | 30 +-- .../monocle/state/StateOptionalSyntax.scala | 26 +-- .../monocle/state/StateSetterSyntax.scala | 20 -- .../PlatformSpecificTestInstances.scala | 4 +- .../src/test/scala/monocle/FoldSpec.scala | 15 +- .../src/test/scala/monocle/GetterSpec.scala | 31 +-- .../src/test/scala/monocle/IsoSpec.scala | 24 +-- .../src/test/scala/monocle/LensSpec.scala | 20 +- .../src/test/scala/monocle/MonocleSuite.scala | 1 - .../src/test/scala/monocle/OptionalSpec.scala | 9 +- .../src/test/scala/monocle/PrismSpec.scala | 5 +- .../src/test/scala/monocle/SetterSpec.scala | 10 +- .../test/scala/monocle/TestInstances.scala | 151 +++----------- .../test/scala/monocle/TraversalSpec.scala | 24 +-- .../scala/monocle/function/Cons1Spec.scala | 2 +- .../test/scala/monocle/function/Data.scala | 23 +- .../scala/monocle/function/Snoc1Spec.scala | 2 +- .../scala/monocle/generic/CoproductSpec.scala | 4 +- .../scala/monocle/generic/HListSpec.scala | 12 +- .../scala/monocle/generic/ProductSpec.scala | 6 +- .../test/scala/monocle/refined/CharSpec.scala | 7 +- .../scala/monocle/refined/StringsSpec.scala | 8 +- .../test/scala/monocle/std/CofreeSpec.scala | 4 +- .../scala/monocle/std/DisjunctionSpec.scala | 17 -- .../test/scala/monocle/std/Either3Spec.scala | 10 - .../test/scala/monocle/std/IListSpec.scala | 17 -- .../src/test/scala/monocle/std/IMapSpec.scala | 14 -- .../src/test/scala/monocle/std/ISetSpec.scala | 11 - .../test/scala/monocle/std/MaybeSpec.scala | 17 -- .../scala/monocle/std/NonEmptyListSpec.scala | 3 +- .../test/scala/monocle/std/OneAndSpec.scala | 2 +- .../src/test/scala/monocle/std/TreeSpec.scala | 20 -- .../src/test/scala/monocle/std/TrySpec.scala | 6 +- .../test/scala/monocle/std/Tuple1Spec.scala | 6 - .../scala/monocle/std/ValidationSpec.scala | 2 +- .../monocle/unsafe/UnsafeSelectSpec.scala | 4 +- .../scala/other/MacroOutSideMonocleSpec.scala | 21 +- 138 files changed, 466 insertions(+), 1570 deletions(-) delete mode 100644 core/shared/src/main/scala/monocle/std/Disjunction.scala delete mode 100644 core/shared/src/main/scala/monocle/std/Either3.scala delete mode 100644 core/shared/src/main/scala/monocle/std/IList.scala delete mode 100644 core/shared/src/main/scala/monocle/std/IMap.scala delete mode 100644 core/shared/src/main/scala/monocle/std/Maybe.scala delete mode 100644 core/shared/src/main/scala/monocle/std/Tree.scala delete mode 100644 core/shared/src/main/scala/monocle/syntax/Traversal.scala delete mode 100644 example/src/test/scala/monocle/std/TreeExample.scala delete mode 100644 state/shared/src/main/scala/monocle/state/StateSetterSyntax.scala delete mode 100644 test/shared/src/test/scala/monocle/std/DisjunctionSpec.scala delete mode 100644 test/shared/src/test/scala/monocle/std/Either3Spec.scala delete mode 100644 test/shared/src/test/scala/monocle/std/IListSpec.scala delete mode 100644 test/shared/src/test/scala/monocle/std/IMapSpec.scala delete mode 100644 test/shared/src/test/scala/monocle/std/ISetSpec.scala delete mode 100644 test/shared/src/test/scala/monocle/std/MaybeSpec.scala delete mode 100644 test/shared/src/test/scala/monocle/std/TreeSpec.scala diff --git a/bench/src/main/scala/monocle/bench/MonocleLensBench.scala b/bench/src/main/scala/monocle/bench/MonocleLensBench.scala index 5c9b1cd40..a4e66488b 100644 --- a/bench/src/main/scala/monocle/bench/MonocleLensBench.scala +++ b/bench/src/main/scala/monocle/bench/MonocleLensBench.scala @@ -7,7 +7,7 @@ import monocle.bench.BenchModel._ import monocle.bench.input.Nested0Input import org.openjdk.jmh.annotations._ -import scalaz.std.option._ +import cats.instances.option._ @BenchmarkMode(Array(Mode.AverageTime)) @OutputTimeUnit(TimeUnit.MICROSECONDS) diff --git a/bench/src/main/scala/monocle/bench/MonocleMacroLensBench.scala b/bench/src/main/scala/monocle/bench/MonocleMacroLensBench.scala index b9105052f..7e89aac77 100644 --- a/bench/src/main/scala/monocle/bench/MonocleMacroLensBench.scala +++ b/bench/src/main/scala/monocle/bench/MonocleMacroLensBench.scala @@ -7,7 +7,7 @@ import monocle.bench.input.Nested0Input import monocle.macros.GenLens import org.openjdk.jmh.annotations._ -import scalaz.std.option._ +import cats.instances.option._ @BenchmarkMode(Array(Mode.AverageTime)) @OutputTimeUnit(TimeUnit.MICROSECONDS) diff --git a/bench/src/main/scala/monocle/bench/MonocleTraversalBench.scala b/bench/src/main/scala/monocle/bench/MonocleTraversalBench.scala index 4dfeaf323..83736e3e9 100644 --- a/bench/src/main/scala/monocle/bench/MonocleTraversalBench.scala +++ b/bench/src/main/scala/monocle/bench/MonocleTraversalBench.scala @@ -4,7 +4,7 @@ import monocle.bench.BenchModel._ import monocle.{PTraversal, Traversal} import org.openjdk.jmh.annotations.{Benchmark, Scope, State} -import scalaz.std.map._ +import cats.instances.map._ @State(Scope.Benchmark) class MonocleTraversalBench { @@ -20,4 +20,4 @@ class MonocleTraversalBench { @Benchmark def collectionGetAll() = iMapTraversal.getAll(map) @Benchmark def collectionSet() = iMapTraversal.set(12)(map) @Benchmark def collectionModify() = iMapTraversal.modify(_ + 1)(map) -} \ No newline at end of file +} diff --git a/build.sbt b/build.sbt index b57bc374e..b853c039f 100644 --- a/build.sbt +++ b/build.sbt @@ -41,17 +41,23 @@ lazy val buildSettings = Seq( scmInfo := Some(ScmInfo(url("https://github.com/julien-truffaut/Monocle"), "scm:git:git@github.com:julien-truffaut/Monocle.git")) ) -lazy val scalaz = Def.setting("org.scalaz" %%% "scalaz-core" % "7.2.13") -lazy val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.2") +lazy val catsVersion = "1.0.0-MF" -lazy val refinedDep = Def.setting("eu.timepit" %%% "refined" % "0.6.1") -lazy val refinedScalacheck = Def.setting("eu.timepit" %%% "refined-scalacheck" % "0.6.1" % "test") +lazy val cats = Def.setting("org.typelevel" %%% "cats-core" % catsVersion) +lazy val catsFree = Def.setting("org.typelevel" %%% "cats-free" % catsVersion) +lazy val catsLaws = Def.setting("org.typelevel" %%% "cats-laws" % catsVersion) +lazy val newts = Def.setting("com.github.julien-truffaut" %%% "newts-core" % "0.3.0-MF-2") +lazy val scalaz = Def.setting("org.scalaz" %%% "scalaz-core" % "7.2.13") +lazy val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.2") -lazy val discipline = Def.setting("org.typelevel" %%% "discipline" % "0.7.3") -lazy val scalacheck = Def.setting("org.scalacheck" %%% "scalacheck" % "1.13.5") -lazy val scalatest = Def.setting("org.scalatest" %%% "scalatest" % "3.0.3" % "test") +lazy val refinedDep = Def.setting("eu.timepit" %%% "refined" % "0.6.1") +lazy val refinedScalacheck = Def.setting("eu.timepit" %%% "refined-scalacheck" % "0.6.1" % "test") -lazy val macroCompat = Def.setting("org.typelevel" %%% "macro-compat" % "1.1.1") +lazy val discipline = Def.setting("org.typelevel" %%% "discipline" % "0.7.3") +lazy val scalacheck = Def.setting("org.scalacheck" %%% "scalacheck" % "1.13.5") +lazy val scalatest = Def.setting("org.scalatest" %%% "scalatest" % "3.0.3" % "test") + +lazy val macroCompat = Def.setting("org.typelevel" %%% "macro-compat" % "1.1.1") lazy val macroVersion = "2.1.0" lazy val paradisePlugin = "org.scalamacros" % "paradise" % macroVersion cross CrossVersion.patch @@ -127,7 +133,7 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform) _.nativeSettings(monocleNativeSettings) ) .jvmSettings(mimaSettings("core"): _*) - .settings(libraryDependencies += scalaz.value) + .settings(libraryDependencies ++= Seq(cats.value, catsFree.value, newts.value)) .jvmSettings( libraryDependencies ++= PartialFunction.condOpt(CrossVersion.partialVersion(scalaVersion.value)) { case Some((2, 11)) => "org.scala-lang.modules" %% "scala-java8-compat" % "0.7.0" @@ -143,7 +149,7 @@ lazy val generic = crossProject(JVMPlatform, JSPlatform).dependsOn(core) _.jsSettings(monocleJsSettings) ) .jvmSettings(mimaSettings("generic"): _*) - .settings(libraryDependencies ++= Seq(scalaz.value, shapeless.value)) + .settings(libraryDependencies ++= Seq(cats.value, shapeless.value)) lazy val refinedJVM = refined.jvm lazy val refinedJS = refined.js @@ -153,7 +159,7 @@ lazy val refined = crossProject(JVMPlatform, JSPlatform).dependsOn(core) _.jvmSettings(monocleJvmSettings), _.jsSettings(monocleJsSettings) ) - .settings(libraryDependencies ++= Seq(scalaz.value, refinedDep.value)) + .settings(libraryDependencies ++= Seq(cats.value, refinedDep.value)) lazy val lawJVM = law.jvm lazy val lawJS = law.js @@ -198,7 +204,7 @@ lazy val state = crossProject(JVMPlatform, JSPlatform, NativePlatform).dep _.jsSettings(monocleJsSettings), _.nativeSettings(monocleNativeSettings) ) - .settings(libraryDependencies ++= Seq(scalaz.value)) + .settings(libraryDependencies ++= Seq(cats.value)) lazy val unsafeJVM = unsafe.jvm lazy val unsafeJS = unsafe.js @@ -209,7 +215,7 @@ lazy val unsafe = crossProject(JVMPlatform, JSPlatform).dependsOn(core) _.jsSettings(monocleJsSettings) ) .jvmSettings(mimaSettings("unsafe"): _*) - .settings(libraryDependencies ++= Seq(scalaz.value, shapeless.value)) + .settings(libraryDependencies ++= Seq(cats.value, shapeless.value)) lazy val testJVM = test.jvm lazy val testJS = test.js @@ -221,14 +227,14 @@ lazy val test = crossProject(JVMPlatform, JSPlatform).dependsOn(core, generic ) .settings(noPublishSettings: _*) .settings( - libraryDependencies ++= Seq(scalaz.value, shapeless.value, scalatest.value, refinedScalacheck.value, compilerPlugin(paradisePlugin)) + libraryDependencies ++= Seq(cats.value, catsLaws.value, shapeless.value, scalatest.value, refinedScalacheck.value, compilerPlugin(paradisePlugin)) ) lazy val testNative = project.in(file("testNative")).dependsOn(coreNative, stateNative) .settings(moduleName := "monocle-test-native") .settings(monocleNativeSettings) .settings(noPublishSettings) .settings( - libraryDependencies ++= Seq(scalaz.value) + libraryDependencies ++= Seq(cats.value) ) .enablePlugins(ScalaNativePlugin) @@ -237,6 +243,7 @@ lazy val bench = project.dependsOn(coreJVM, genericJVM, macrosJVM) .settings(monocleJvmSettings) .settings(noPublishSettings) .settings(libraryDependencies ++= Seq( + scalaz.value, shapeless.value, compilerPlugin(paradisePlugin) )).enablePlugins(JmhPlugin) @@ -246,7 +253,7 @@ lazy val example = project.dependsOn(coreJVM, genericJVM, refinedJVM, macrosJVM, .settings(monocleJvmSettings) .settings(noPublishSettings) .settings( - libraryDependencies ++= Seq(scalaz.value, shapeless.value, scalatest.value, compilerPlugin(paradisePlugin)) + libraryDependencies ++= Seq(cats.value, shapeless.value, scalatest.value, compilerPlugin(paradisePlugin)) ) lazy val docs = project.dependsOn(coreJVM, unsafeJVM, macrosJVM, example) @@ -259,7 +266,7 @@ lazy val docs = project.dependsOn(coreJVM, unsafeJVM, macrosJVM, example) .settings(docSettings) .settings(tutScalacOptions ~= (_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-dead-code")))) .settings( - libraryDependencies ++= Seq(scalaz.value, shapeless.value, compilerPlugin(paradisePlugin)) + libraryDependencies ++= Seq(cats.value, shapeless.value, compilerPlugin(paradisePlugin)) ) lazy val docsMappingsAPIDir = settingKey[String]("Name of subdirectory in site target directory for api docs") diff --git a/core/shared/src/main/scala/monocle/Fold.scala b/core/shared/src/main/scala/monocle/Fold.scala index c9fd173e0..1f083caa8 100644 --- a/core/shared/src/main/scala/monocle/Fold.scala +++ b/core/shared/src/main/scala/monocle/Fold.scala @@ -1,13 +1,12 @@ package monocle -import monocle.function.fields.{first, second} -import scalaz.std.anyVal._ -import scalaz.std.list._ -import scalaz.std.option._ -import scalaz.syntax.std.boolean._ -import scalaz.syntax.std.option._ -import scalaz.syntax.tag._ -import scalaz.{Choice, Foldable, Monoid, Unzip, \/} +import cats.{Foldable, Monoid} +import cats.arrow.Choice +import cats.instances.int._ +import cats.instances.list._ +import cats.syntax.either._ +import newts.syntax.all._ +import scala.{Either => \/} /** * A [[Fold]] can be seen as a [[Getter]] with many targets or @@ -38,23 +37,23 @@ abstract class Fold[S, A] extends Serializable { self => /** find the first target matching the predicate */ @inline final def find(p: A => Boolean): S => Option[A] = - foldMap(a => (if(p(a)) Some(a) else None).first)(_).unwrap + foldMap(a => (if(p(a)) Some(a) else None).asFirstOption)(_).unwrap /** get the first target */ @inline final def headOption(s: S): Option[A] = - foldMap(Option(_).first)(s).unwrap + foldMap(Option(_).asFirstOption)(s).unwrap /** get the last target */ @inline final def lastOption(s: S): Option[A] = - foldMap(Option(_).last)(s).unwrap + foldMap(Option(_).asLastOption)(s).unwrap /** check if at least one target satisfies the predicate */ @inline final def exist(p: A => Boolean): S => Boolean = - foldMap(p(_).disjunction)(_).unwrap + foldMap(p(_).asAny)(_).unwrap /** check if all targets satisfy the predicate */ @inline final def all(p: A => Boolean): S => Boolean = - foldMap(p(_).conjunction)(_).unwrap + foldMap(p(_).asAll)(_).unwrap /** calculate the number of targets */ @inline final def length(s: S): Int = @@ -62,7 +61,7 @@ abstract class Fold[S, A] extends Serializable { self => /** check if there is no target */ @inline final def isEmpty(s: S): Boolean = - foldMap(_ => false.conjunction)(s).unwrap + foldMap(_ => false.asAll)(s).unwrap /** check if there is at least one target */ @inline final def nonEmpty(s: S): Boolean = @@ -161,7 +160,7 @@ object Fold extends FoldInstances { def select[A](p: A => Boolean): Fold[A, A] = new Fold[A, A] { def foldMap[M: Monoid](f: A => M)(s: A): M = - if (p(s)) f(s) else Monoid[M].zero + if (p(s)) f(s) else Monoid[M].empty } /** [[Fold]] that points to nothing */ @@ -178,7 +177,7 @@ object Fold extends FoldInstances { sealed abstract class FoldInstances { implicit val foldChoice: Choice[Fold] = new Choice[Fold]{ - def choice[A, B, C](f: => Fold[A, C], g: => Fold[B, C]): Fold[A \/ B, C] = + def choice[A, B, C](f: Fold[A, C], g: Fold[B, C]): Fold[A \/ B, C] = f choice g def id[A]: Fold[A, A] = @@ -187,9 +186,4 @@ sealed abstract class FoldInstances { def compose[A, B, C](f: Fold[B, C], g: Fold[A, B]): Fold[A, C] = g composeFold f } - - implicit def foldUnzip[S]: Unzip[Fold[S, ?]] = new Unzip[Fold[S, ?]] { - override def unzip[A, B](f: Fold[S, (A, B)]): (Fold[S, A], Fold[S, B]) = - (f composeLens first, f composeLens second) - } } diff --git a/core/shared/src/main/scala/monocle/Getter.scala b/core/shared/src/main/scala/monocle/Getter.scala index e2b8d08dd..320db2640 100644 --- a/core/shared/src/main/scala/monocle/Getter.scala +++ b/core/shared/src/main/scala/monocle/Getter.scala @@ -1,6 +1,9 @@ package monocle -import scalaz.{Arrow, Choice, Monoid, Unzip, Zip, \/} +import cats.{Monoid, Cartesian => Zip} +import cats.arrow.{Arrow, Choice} +import cats.implicits._ +import scala.{Either => \/} /** * A [[Getter]] can be seen as a glorified get method between @@ -135,7 +138,7 @@ object Getter extends GetterInstances { sealed abstract class GetterInstances extends GetterInstances0 { implicit val getterArrow: Arrow[Getter] = new Arrow[Getter]{ - def arr[A, B](f: (A) => B): Getter[A, B] = + def lift[A, B](f: (A) => B): Getter[A, B] = Getter(f) def first[A, B, C](f: Getter[A, B]): Getter[(A, C), (B, C)] = @@ -152,18 +155,13 @@ sealed abstract class GetterInstances extends GetterInstances0 { } implicit def getterZip[S]: Zip[Getter[S, ?]] = new Zip[Getter[S, ?]] { - override def zip[A, B](a: => Getter[S, A], b: => Getter[S, B]) = a zip b - } - - implicit def getterUnzip[S]: Unzip[Getter[S, ?]] = new Unzip[Getter[S, ?]] { - override def unzip[A, B](g: Getter[S, (A, B)]): (Getter[S, A], Getter[S, B]) = - (Getter[S, A](s => g.get(s)._1), Getter[S, B](s => g.get(s)._2)) + override def product[A, B](a: Getter[S, A], b: Getter[S, B]) = a zip b } } sealed abstract class GetterInstances0 { implicit val getterChoice: Choice[Getter] = new Choice[Getter]{ - def choice[A, B, C](f: => Getter[A, C], g: => Getter[B, C]): Getter[A \/ B, C] = + def choice[A, B, C](f: Getter[A, C], g: Getter[B, C]): Getter[A \/ B, C] = f choice g def id[A]: Getter[A, A] = @@ -172,4 +170,4 @@ sealed abstract class GetterInstances0 { def compose[A, B, C](f: Getter[B, C], g: Getter[A, B]): Getter[A, C] = g composeGetter f } -} \ No newline at end of file +} diff --git a/core/shared/src/main/scala/monocle/Iso.scala b/core/shared/src/main/scala/monocle/Iso.scala index 87387b3b7..ccf219000 100644 --- a/core/shared/src/main/scala/monocle/Iso.scala +++ b/core/shared/src/main/scala/monocle/Iso.scala @@ -1,9 +1,10 @@ package monocle -import scalaz.Isomorphism.{<=>, <~>} -import scalaz.Leibniz.=== -import scalaz.Liskov.<~< -import scalaz.{Applicative, Category, Functor, Monoid, Split, \/} +import cats.{Applicative, Functor, Monoid} +import cats.arrow.Category +import cats.evidence.{<~<, Is => ===} +import cats.syntax.either._ +import scala.{Either => \/} /** * [[Iso]] is a type alias for [[PIso]] where `S` = `A` and `T` = `B`: @@ -276,7 +277,7 @@ abstract class PIso[S, T, A, B] extends Serializable { self => /*************************************************************************/ def apply()(implicit ev: B === Unit): T = - ev.subst[PIso[S, T, A, ?]](self).reverseGet(()) + ev.substitute[PIso[S, T, A, ?]](self).reverseGet(()) def apply(b: B): T = reverseGet(b) @@ -337,10 +338,6 @@ object PIso extends IsoInstances { def reverse: PIso[S, T, S, T] = self } } - - /** transform a natural transformation in a [[PIso]] */ - def fromIsoFunctor[F[_], G[_], A, B](isoFunctor: F <~> G): PIso[F[A], F[B], G[A], G[B]] = - PIso(isoFunctor.to.apply[A])(isoFunctor.from.apply[B]) } object Iso { @@ -351,23 +348,9 @@ object Iso { /** alias for [[PIso]] id when S = T and A = B */ def id[S]: Iso[S, S] = PIso.id[S, S] - - /** transform an Iso in a [[Iso]] */ - def fromIsoSet[A, B](isoSet: A <=> B): Iso[A, B] = - Iso(isoSet.to)(isoSet.from) -} - -sealed abstract class IsoInstances extends IsoInstances0 { - implicit val isoSplit: Split[Iso] = new Split[Iso] { - def split[A, B, C, D](f: Iso[A, B], g: Iso[C, D]): Iso[(A, C), (B, D)] = - f split g - - def compose[A, B, C](f: Iso[B, C], g: Iso[A, B]): Iso[A, C] = - g composeIso f - } } -sealed abstract class IsoInstances0 { +sealed abstract class IsoInstances { implicit val isoCategory: Category[Iso] = new Category[Iso]{ def id[A]: Iso[A, A] = Iso.id[A] diff --git a/core/shared/src/main/scala/monocle/Lens.scala b/core/shared/src/main/scala/monocle/Lens.scala index 7e250d73d..43675194b 100644 --- a/core/shared/src/main/scala/monocle/Lens.scala +++ b/core/shared/src/main/scala/monocle/Lens.scala @@ -1,7 +1,9 @@ package monocle -import monocle.function.fields.{first, second} -import scalaz.{Applicative, Choice, IndexedStore, Functor, Monoid, Split, Unzip, \/} +import cats.{Applicative, Functor, Monoid} +import cats.arrow.Choice +import cats.syntax.either._ +import scala.{Either => \/} /** * A [[PLens]] can be seen as a pair of functions: @@ -223,12 +225,6 @@ object PLens extends LensInstances { _.fold(identity, identity) )(t => _.bimap(_ => t, _ => t)) - /** - * create a [[PLens]] from a context (indexed store) coalgebra. - */ - def fromStore[S, T, A, B](f: S => IndexedStore[A, B, T]): PLens[S, T, A, B] = - PLens[S, T, A, B](s => f(s).pos)(b => s => f(s).peek(b)) - /** * create a [[PLens]] using a pair of functions: one to get the target, one to set the target. * @see macro module for methods generating [[PLens]] with less boiler plate @@ -262,9 +258,9 @@ object Lens { PLens(get)(set) } -sealed abstract class LensInstances extends LensInstances0 { +sealed abstract class LensInstances { implicit val lensChoice: Choice[Lens] = new Choice[Lens] { - def choice[A, B, C](f: => Lens[A, C], g: => Lens[B, C]): Lens[A \/ B, C] = + def choice[A, B, C](f: Lens[A, C], g: Lens[B, C]): Lens[A \/ B, C] = f choice g def id[A]: Lens[A, A] = @@ -273,19 +269,4 @@ sealed abstract class LensInstances extends LensInstances0 { def compose[A, B, C](f: Lens[B, C], g: Lens[A, B]): Lens[A, C] = g composeLens f } - - implicit def lensUnzip[S]: Unzip[Lens[S, ?]] = new Unzip[Lens[S, ?]] { - def unzip[A, B](f: Lens[S, (A, B)]): (Lens[S, A], Lens[S, B]) = - (f composeLens first, f composeLens second) - } -} - -sealed abstract class LensInstances0 { - implicit val lensSplit: Split[Lens] = new Split[Lens] { - def split[A, B, C, D](f: Lens[A, B], g: Lens[C, D]): Lens[(A, C), (B, D)] = - f split g - - def compose[A, B, C](f: Lens[B, C], g: Lens[A, B]): Lens[A, C] = - g composeLens f - } } diff --git a/core/shared/src/main/scala/monocle/Optional.scala b/core/shared/src/main/scala/monocle/Optional.scala index 39190aafc..e40492b73 100644 --- a/core/shared/src/main/scala/monocle/Optional.scala +++ b/core/shared/src/main/scala/monocle/Optional.scala @@ -1,7 +1,9 @@ package monocle -import monocle.function.fields.{first, second} -import scalaz.{Applicative, Choice, Monoid, Unzip, \/} +import cats.{Applicative, Monoid} +import cats.arrow.Choice +import cats.syntax.either._ +import scala.{Either => \/} /** * A [[POptional]] can be seen as a pair of functions: @@ -180,7 +182,7 @@ abstract class POptional[S, T, A, B] extends Serializable { self => /** view a [[POptional]] as a [[Fold]] */ @inline final def asFold: Fold[S, A] = new Fold[S, A]{ def foldMap[M: Monoid](f: A => M)(s: S): M = - self.getOption(s) map f getOrElse Monoid[M].zero + self.getOption(s) map f getOrElse Monoid[M].empty } /** view a [[POptional]] as a [[PSetter]] */ @@ -269,7 +271,7 @@ object Optional { sealed abstract class OptionalInstances { implicit val optionalChoice: Choice[Optional] = new Choice[Optional] { - def choice[A, B, C](f: => Optional[A, C], g: => Optional[B, C]): Optional[A \/ B, C] = + def choice[A, B, C](f: Optional[A, C], g: Optional[B, C]): Optional[A \/ B, C] = f choice g def id[A]: Optional[A, A] = @@ -278,9 +280,4 @@ sealed abstract class OptionalInstances { def compose[A, B, C](f: Optional[B, C], g: Optional[A, B]): Optional[A, C] = g composeOptional f } - - implicit def optionalUnzip[S]: Unzip[Optional[S, ?]] = new Unzip[Optional[S, ?]] { - override def unzip[A, B](f: Optional[S, (A, B)]): (Optional[S, A], Optional[S, B]) = - (f composeLens first, f composeLens second) - } } diff --git a/core/shared/src/main/scala/monocle/Prism.scala b/core/shared/src/main/scala/monocle/Prism.scala index b1086ea3c..1f5448730 100644 --- a/core/shared/src/main/scala/monocle/Prism.scala +++ b/core/shared/src/main/scala/monocle/Prism.scala @@ -1,9 +1,11 @@ package monocle -import scalaz.Leibniz.=== -import scalaz.Liskov.<~< -import scalaz.{Applicative, Category, Equal, Monoid, Traverse, \/} -import scalaz.std.option._ +import cats.{Applicative, Eq => Equal, Monoid, Traverse} +import cats.arrow.Category +import cats.evidence.{<~<, Is => ===} +import cats.instances.option._ +import cats.syntax.either._ +import scala.{Either => \/} /** * A [[PPrism]] can be seen as a pair of functions: @@ -195,7 +197,7 @@ abstract class PPrism[S, T, A, B] extends Serializable { self => /** view a [[PPrism]] as a [[Fold]] */ @inline final def asFold: Fold[S, A] = new Fold[S, A]{ def foldMap[M: Monoid](f: A => M)(s: S): M = - getOption(s) map f getOrElse Monoid[M].zero + getOption(s) map f getOrElse Monoid[M].empty } /** view a [[PPrism]] as a [[Setter]] */ @@ -239,7 +241,7 @@ abstract class PPrism[S, T, A, B] extends Serializable { self => /*************************************************************************/ def apply()(implicit ev: B === Unit): T = - ev.subst[PPrism[S, T, A, ?]](self).reverseGet(()) + ev.substitute[PPrism[S, T, A, ?]](self).reverseGet(()) def apply(b: B): T = reverseGet(b) @@ -304,7 +306,7 @@ object Prism { /** a [[Prism]] that checks for equality with a given value */ def only[A](a: A)(implicit A: Equal[A]): Prism[A, Unit] = - Prism[A, Unit](a2 => if(A.equal(a, a2)) Some(()) else None)(_ => a) + Prism[A, Unit](a2 => if(A.eqv(a, a2)) Some(()) else None)(_ => a) } sealed abstract class PrismInstances { diff --git a/core/shared/src/main/scala/monocle/Setter.scala b/core/shared/src/main/scala/monocle/Setter.scala index dc440c15e..63b2e666f 100644 --- a/core/shared/src/main/scala/monocle/Setter.scala +++ b/core/shared/src/main/scala/monocle/Setter.scala @@ -1,7 +1,10 @@ package monocle -import monocle.function.fields.{first, second} -import scalaz.{Choice, Contravariant, Functor, Profunctor, Unzip, \/} +import cats.Functor +import cats.arrow.Choice +import cats.functor.{Contravariant, Profunctor} +import cats.syntax.either._ +import scala.{Either => \/} /** * A [[PSetter]] is a generalisation of Functor map: @@ -115,7 +118,7 @@ object PSetter extends SetterInstances { _modify(_ => b) } - /** create a [[PSetter]] from a scalaz.Functor */ + /** create a [[PSetter]] from a cats.Functor */ def fromFunctor[F[_], A, B](implicit F: Functor[F]): PSetter[F[A], F[B], A, B] = PSetter[F[A], F[B], A, B](f => F.map(_)(f)) @@ -125,7 +128,7 @@ object PSetter extends SetterInstances { /** create a [[PSetter]] from a Profunctor */ def fromProfunctor[P[_, _], A, B, C](implicit P: Profunctor[P]): PSetter[P[B, C], P[A, C], A, B] = - PSetter[P[B, C], P[A, C], A, B](f => P.mapfst(_)(f)) + PSetter[P[B, C], P[A, C], A, B](f => P.lmap(_)(f)) } @@ -153,12 +156,7 @@ sealed abstract class SetterInstances { def id[A]: Setter[A, A] = Setter.id - def choice[A, B, C](f1: => Setter[A, C], f2: => Setter[B, C]): Setter[A \/ B, C] = + def choice[A, B, C](f1: Setter[A, C], f2: Setter[B, C]): Setter[A \/ B, C] = f1 choice f2 } - - implicit def setterUnzip[S]: Unzip[Setter[S, ?]] = new Unzip[Setter[S, ?]] { - override def unzip[A, B](f: Setter[S, (A, B)]): (Setter[S, A], Setter[S, B]) = - (f composeLens first, f composeLens second) - } } diff --git a/core/shared/src/main/scala/monocle/Traversal.scala b/core/shared/src/main/scala/monocle/Traversal.scala index d1a67c55b..07fd63324 100644 --- a/core/shared/src/main/scala/monocle/Traversal.scala +++ b/core/shared/src/main/scala/monocle/Traversal.scala @@ -1,15 +1,13 @@ package monocle -import monocle.function.fields.{first, second} -import scalaz.Id.Id -import scalaz.std.anyVal._ -import scalaz.std.list._ -import scalaz.std.option._ -import scalaz.syntax.functor._ -import scalaz.syntax.std.boolean._ -import scalaz.syntax.std.option._ -import scalaz.syntax.tag._ -import scalaz.{Applicative, Choice, Const, IndexedStore, FreeAp, Functor, Monoid, Traverse, Unzip, \/, ~>} +import cats.{Applicative, Functor, Id, Monoid, Traverse} +import cats.arrow.Choice +import cats.data.Const +import cats.instances.int._ +import cats.instances.list._ +import cats.syntax.either._ +import newts.syntax.all._ +import scala.{Either => \/} /** * A [[PTraversal]] can be seen as a [[POptional]] generalised to 0 to n targets @@ -51,23 +49,23 @@ abstract class PTraversal[S, T, A, B] extends Serializable { self => /** find the first target matching the predicate */ @inline final def find(p: A => Boolean): S => Option[A] = - foldMap(a => (if(p(a)) Some(a) else None).first)(_).unwrap + foldMap(a => (if(p(a)) Some(a) else None).asFirstOption)(_).unwrap /** get the first target */ @inline final def headOption(s: S): Option[A] = - foldMap(Option(_).first)(s).unwrap + foldMap(Option(_).asFirstOption)(s).unwrap /** get the last target */ @inline final def lastOption(s: S): Option[A] = - foldMap(Option(_).last)(s).unwrap + foldMap(Option(_).asLastOption)(s).unwrap /** check if at least one target satisfies the predicate */ @inline final def exist(p: A => Boolean): S => Boolean = - foldMap(p(_).disjunction)(_).unwrap + foldMap(p(_).asAny)(_).unwrap /** check if all targets satisfy the predicate */ @inline final def all(p: A => Boolean): S => Boolean = - foldMap(p(_).conjunction)(_).unwrap + foldMap(p(_).asAll)(_).unwrap /** modify polymorphically the target of a [[PTraversal]] with a function */ @inline final def modify(f: A => B): S => T = @@ -93,7 +91,7 @@ abstract class PTraversal[S, T, A, B] extends Serializable { self => /** check if there is no target */ @inline final def isEmpty(s: S): Boolean = - foldMap(_ => false.conjunction)(s).unwrap + foldMap(_ => false.asAll)(s).unwrap /** check if there is at least one target */ @inline final def nonEmpty(s: S): Boolean = @@ -199,39 +197,31 @@ object PTraversal extends TraversalInstances { def apply2[S, T, A, B](get1: S => A, get2: S => A)(_set: (B, B, S) => T): PTraversal[S, T, A, B] = new PTraversal[S, T, A, B] { def modifyF[F[_]: Applicative](f: A => F[B])(s: S): F[T] = - Applicative[F].apply2(f(get1(s)), f(get2(s)))(_set(_, _, s)) + Applicative[F].map2(f(get1(s)), f(get2(s)))(_set(_, _, s)) } def apply3[S, T, A, B](get1: S => A, get2: S => A, get3: S => A)(_set: (B, B, B, S) => T): PTraversal[S, T, A, B] = new PTraversal[S, T, A, B] { def modifyF[F[_]: Applicative](f: A => F[B])(s: S): F[T] = - Applicative[F].apply3(f(get1(s)), f(get2(s)), f(get3(s)))(_set(_, _, _, s)) + Applicative[F].map3(f(get1(s)), f(get2(s)), f(get3(s)))(_set(_, _, _, s)) } def apply4[S, T, A, B](get1: S => A, get2: S => A, get3: S => A, get4: S => A)(_set: (B, B, B, B, S) => T): PTraversal[S, T, A, B] = new PTraversal[S, T, A, B] { def modifyF[F[_]: Applicative](f: A => F[B])(s: S): F[T] = - Applicative[F].apply4(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)))(_set(_, _, _, _, s)) + Applicative[F].map4(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)))(_set(_, _, _, _, s)) } def apply5[S, T, A, B](get1: S => A, get2: S => A, get3: S => A, get4: S => A, get5: S => A)(_set: (B, B, B, B, B, S) => T): PTraversal[S, T, A, B] = new PTraversal[S, T, A, B] { def modifyF[F[_]: Applicative](f: A => F[B])(s: S): F[T] = - Applicative[F].apply5(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)))(_set(_, _, _, _, _, s)) + Applicative[F].map5(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)))(_set(_, _, _, _, _, s)) } def apply6[S, T, A, B](get1: S => A, get2: S => A, get3: S => A, get4: S => A, get5: S => A, get6: S => A)(_set: (B, B, B, B, B, B, S) => T): PTraversal[S, T, A, B] = new PTraversal[S, T, A, B] { def modifyF[F[_]: Applicative](f: A => F[B])(s: S): F[T] = - Applicative[F].apply6(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)))(_set(_, _, _, _, _, _, s)) - } - - def fromStore[S, T, A, B](f: S => FreeAp[IndexedStore[A, B, ?], T]) = - new PTraversal[S, T, A, B] { - def modifyF[F[_]: Applicative](g: A => F[B])(s: S): F[T] = - f(s).foldMap(new (IndexedStore[A, B, ?] ~> F) { - def apply[X](is: IndexedStore[A, B, X]) = g(is.pos).map(is.set) - }) + Applicative[F].map6(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)))(_set(_, _, _, _, _, _, s)) } } @@ -273,7 +263,7 @@ object Traversal { new PTraversal[S, S, A, A] { def modifyF[F[_] : Applicative](f: A => F[A])(s: S): F[S] = { xs.foldLeft(Applicative[F].pure(s))((fs, lens) => - Applicative[F].apply2(f(lens.get(s)), fs)((a, s) => lens.set(a)(s)) + Applicative[F].map2(f(lens.get(s)), fs)((a, s) => lens.set(a)(s)) ) } } @@ -288,12 +278,7 @@ sealed abstract class TraversalInstances { def id[A]: Traversal[A, A] = Traversal.id - def choice[A, B, C](f1: => Traversal[A, C], f2: => Traversal[B, C]): Traversal[A \/ B, C] = + def choice[A, B, C](f1: Traversal[A, C], f2: Traversal[B, C]): Traversal[A \/ B, C] = f1 choice f2 } - - implicit def traversalUnzip[S]: Unzip[Traversal[S, ?]] = new Unzip[Traversal[S, ?]] { - override def unzip[A, B](f: Traversal[S, (A, B)]): (Traversal[S, A], Traversal[S, B]) = - (f composeLens first, f composeLens second) - } } diff --git a/core/shared/src/main/scala/monocle/function/At.scala b/core/shared/src/main/scala/monocle/function/At.scala index b69d73ed7..5bebf3c38 100644 --- a/core/shared/src/main/scala/monocle/function/At.scala +++ b/core/shared/src/main/scala/monocle/function/At.scala @@ -47,18 +47,4 @@ object At extends AtFunctions { implicit def atSet[A]: At[Set[A], A, Boolean] = new At[Set[A], A, Boolean] { def at(a: A) = Lens[Set[A], Boolean](_.contains(a))(b => set => if(b) set + a else set - a) } - - /************************************************************************************************/ - /** Scalaz instances */ - /************************************************************************************************/ - - import scalaz.{==>>, ISet, Order} - - implicit def atIMap[K: Order, V]: At[K ==>> V, K, Option[V]] = new At[K ==>> V, K, Option[V]]{ - def at(i: K) = Lens{m: ==>>[K, V] => m.lookup(i)}(optV => map => optV.fold(map - i)(v => map + (i -> v))) - } - - implicit def atISet[A: Order]: At[ISet[A], A, Boolean] = new At[ISet[A], A, Boolean] { - def at(a: A) = Lens[ISet[A], Boolean](_.member(a))(b => set => if(b) set insert a else set delete a) - } -} \ No newline at end of file +} diff --git a/core/shared/src/main/scala/monocle/function/Cons.scala b/core/shared/src/main/scala/monocle/function/Cons.scala index e4653cf0e..4a5ecac3e 100644 --- a/core/shared/src/main/scala/monocle/function/Cons.scala +++ b/core/shared/src/main/scala/monocle/function/Cons.scala @@ -4,7 +4,6 @@ import monocle.function.fields._ import monocle.{Iso, Optional, Prism} import scala.annotation.implicitNotFound -import scalaz.{ICons, INil} /** * Typeclass that defines a [[Prism]] between an `S` and its head `A` and tail `S` @@ -74,17 +73,4 @@ object Cons extends ConsFunctions { case x +: xs => Some((x, xs)) }{ case (a, s) => a +: s } } - - /************************************************************************************************/ - /** Scalaz instances */ - /************************************************************************************************/ - - import scalaz.IList - - implicit def iListCons[A]: Cons[IList[A], A] = new Cons[IList[A], A]{ - val cons = Prism[IList[A], (A, IList[A])]{ - case INil() => None - case ICons(x, xs) => Some((x, xs)) - }{ case (a, s) => ICons(a, s) } - } -} \ No newline at end of file +} diff --git a/core/shared/src/main/scala/monocle/function/Cons1.scala b/core/shared/src/main/scala/monocle/function/Cons1.scala index c5c64593e..5f774aa06 100644 --- a/core/shared/src/main/scala/monocle/function/Cons1.scala +++ b/core/shared/src/main/scala/monocle/function/Cons1.scala @@ -72,29 +72,32 @@ object Cons1 extends Cons1Functions { } /************************************************************************************************/ - /** Scalaz instances */ + /** Cats instances */ /************************************************************************************************/ - import scalaz.{Cofree, IList, NonEmptyList, OneAnd} + import cats.Now + import cats.data.{NonEmptyList, OneAnd} + import cats.free.Cofree + import scala.{List => IList} implicit def cofreeCons1[S[_], A]: Cons1[Cofree[S, A], A, S[Cofree[S, A]]] = new Cons1[Cofree[S, A], A, S[Cofree[S, A]]] { val cons1: Iso[Cofree[S, A], (A, S[Cofree[S, A]])] = - Iso((c: Cofree[S, A]) => (c.head, c.tail)){ case (h, t) => Cofree(h, t) } + Iso((c: Cofree[S, A]) => (c.head, c.tail.value)){ case (h, t) => Cofree(h, Now(t)) } /** Overridden to prevent forcing evaluation of the `tail` when we're only * interested in using the `head` */ override def head: Lens[Cofree[S, A], A] = - Lens((c: Cofree[S, A]) => c.head)(h => c => Cofree.delay(h, c.tail)) + Lens((c: Cofree[S, A]) => c.head)(h => c => Cofree(h, c.tail)) } implicit def nelCons1[A]: Cons1[NonEmptyList[A], A, IList[A]] = new Cons1[NonEmptyList[A],A,IList[A]]{ val cons1: Iso[NonEmptyList[A], (A, IList[A])] = - Iso((nel: NonEmptyList[A]) => (nel.head,nel.tail)){case (h,t) => NonEmptyList.nel(h, t)} + Iso((nel: NonEmptyList[A]) => (nel.head,nel.tail)){case (h,t) => NonEmptyList(h, t)} } implicit def oneAndCons1[T[_], A]: Cons1[OneAnd[T, A], A, T[A]] = new Cons1[OneAnd[T, A], A, T[A]] { val cons1 = Iso[OneAnd[T, A], (A, T[A])](o => (o.head, o.tail)){ case (h, t) => OneAnd(h, t)} } -} \ No newline at end of file +} diff --git a/core/shared/src/main/scala/monocle/function/Each.scala b/core/shared/src/main/scala/monocle/function/Each.scala index dcb20742f..6ac537fc4 100644 --- a/core/shared/src/main/scala/monocle/function/Each.scala +++ b/core/shared/src/main/scala/monocle/function/Each.scala @@ -3,7 +3,7 @@ package monocle.function import monocle.{Iso, PTraversal, Traversal} import scala.annotation.implicitNotFound -import scalaz.{Applicative, Traverse} +import cats.{Applicative, Traverse} /** * Typeclass that defines a [[Traversal]] from a monomorphic container `S` to all of its elements of type `A` @@ -38,10 +38,10 @@ object Each extends EachFunctions { /************************************************************************************************/ /** Std instances */ /************************************************************************************************/ - import scalaz.std.list._ - import scalaz.std.map._ - import scalaz.std.stream._ - import scalaz.std.vector._ + import cats.instances.list._ + import cats.instances.map._ + import cats.instances.stream._ + import cats.instances.vector._ import scala.util.Try implicit def eitherEach[A, B]: Each[Either[A, B], B] = new Each[Either[A, B], B] { @@ -93,36 +93,23 @@ object Each extends EachFunctions { implicit def vectorEach[A]: Each[Vector[A], A] = fromTraverse /************************************************************************************************/ - /** Scalaz instances */ + /** Cats instances */ /************************************************************************************************/ - import scalaz.{==>>, \/, Cofree, IList, Maybe, NonEmptyList, OneAnd, Tree, Validation} + import cats.data.{NonEmptyList, OneAnd, Validated => Validation} + import cats.free.Cofree implicit def cofreeEach[S[_]: Traverse, A]: Each[Cofree[S, A], A] = fromTraverse[Cofree[S, ?], A] - implicit def disjunctionEach[A, B]: Each[A \/ B, B] = new Each[A \/ B, B] { - def each = monocle.std.disjunction.right.asTraversal - } - - implicit def iListEach[A]: Each[IList[A], A] = fromTraverse - - implicit def iMapEach[K, V]: Each[K ==>> V, V] = fromTraverse[K ==>> ?, V] - - implicit def maybeEach[A]: Each[Maybe[A], A] = new Each[Maybe[A], A]{ - def each = monocle.std.maybe.just.asTraversal - } - implicit def nelEach[A]: Each[NonEmptyList[A], A] = fromTraverse implicit def oneAndEach[T[_], A](implicit ev: Each[T[A], A]): Each[OneAnd[T, A], A] = new Each[OneAnd[T, A], A]{ val each = new Traversal[OneAnd[T, A], A]{ def modifyF[F[_]: Applicative](f: A => F[A])(s: OneAnd[T, A]): F[OneAnd[T, A]] = - Applicative[F].apply2(f(s.head), ev.each.modifyF(f)(s.tail))((head, tail) => new OneAnd(head, tail)) + Applicative[F].map2(f(s.head), ev.each.modifyF(f)(s.tail))((head, tail) => new OneAnd(head, tail)) } } - implicit def treeEach[A]: Each[Tree[A], A] = fromTraverse - implicit def validationEach[A, B]: Each[Validation[A, B], B] = new Each[Validation[A, B], B] { def each = monocle.std.validation.success.asTraversal } diff --git a/core/shared/src/main/scala/monocle/function/Empty.scala b/core/shared/src/main/scala/monocle/function/Empty.scala index f7652f763..4c4769835 100644 --- a/core/shared/src/main/scala/monocle/function/Empty.scala +++ b/core/shared/src/main/scala/monocle/function/Empty.scala @@ -63,26 +63,4 @@ object Empty extends EmptyFunctions { implicit def vectorEmpty[A]: Empty[Vector[A]] = new Empty[Vector[A]] { val empty = Prism[Vector[A], Unit](v => if(v.isEmpty) Some(()) else None)(_ => Vector.empty) } - - /************************************************************************************************/ - /** Scalaz instances */ - /************************************************************************************************/ - import monocle.std.maybe.nothing - import scalaz.{==>>, IList, ISet, Maybe} - - implicit def iListEmpty[A]: Empty[IList[A]] = new Empty[IList[A]] { - def empty = Prism[IList[A], Unit](l => if(l.isEmpty) Some(()) else None)(_ => IList.empty) - } - - implicit def iMapEmpty[K, V]: Empty[K ==>> V] = new Empty[K ==>> V] { - def empty = Prism[K ==>> V, Unit](m => if(m.isEmpty) Some(()) else None)(_ => ==>>.empty) - } - - implicit def emptyISet[A]: Empty[ISet[A]] = new Empty[ISet[A]] { - def empty = Prism[ISet[A], Unit](s => if(s.isEmpty) Some(()) else None)(_ => ISet.empty[A]) - } - - implicit def maybeEmpty[A]: Empty[Maybe[A]] = new Empty[Maybe[A]]{ - def empty = nothing - } -} \ No newline at end of file +} diff --git a/core/shared/src/main/scala/monocle/function/Field1.scala b/core/shared/src/main/scala/monocle/function/Field1.scala index 315ac3851..0c8abb8ed 100644 --- a/core/shared/src/main/scala/monocle/function/Field1.scala +++ b/core/shared/src/main/scala/monocle/function/Field1.scala @@ -54,11 +54,11 @@ object Field1 extends Field1Functions { } /************************************************************************************************/ - /** Scalaz instances */ + /** Cats instances */ /************************************************************************************************/ - import scalaz.OneAnd + import cats.data.OneAnd implicit def oneAndField1[T[_], A]: Field1[OneAnd[T, A], A] = new Field1[OneAnd[T, A], A]{ val first = Lens[OneAnd[T, A], A](_.head)(a => oneAnd => oneAnd.copy(head = a)) } -} \ No newline at end of file +} diff --git a/core/shared/src/main/scala/monocle/function/FilterIndex.scala b/core/shared/src/main/scala/monocle/function/FilterIndex.scala index 14847dc07..1f59af47b 100644 --- a/core/shared/src/main/scala/monocle/function/FilterIndex.scala +++ b/core/shared/src/main/scala/monocle/function/FilterIndex.scala @@ -3,8 +3,8 @@ package monocle.function import monocle.{Iso, Traversal} import scala.annotation.implicitNotFound -import scalaz.syntax.traverse._ -import scalaz.{Applicative, Traverse} +import cats.syntax.traverse._ +import cats.{Applicative, Traverse} /** * Typeclass that defines a [[Traversal]] from an `S` to all its elements `A` whose index `I` in `S` satisfies the predicate @@ -43,19 +43,21 @@ object FilterIndex extends FilterIndexFunctions { /************************************************************************************************/ /** Std instances */ /************************************************************************************************/ - import scalaz.std.list._ - import scalaz.std.stream._ - import scalaz.std.vector._ + import cats.instances.list._ + import cats.instances.stream._ + import cats.instances.vector._ implicit def listFilterIndex[A]: FilterIndex[List[A], Int, A] = fromTraverse(_.zipWithIndex) implicit def mapFilterIndex[K, V]: FilterIndex[Map[K,V], K, V] = new FilterIndex[Map[K, V], K, V] { - import scalaz.syntax.applicative._ + import cats.syntax.applicative._ + import cats.syntax.functor._ + def filterIndex(predicate: K => Boolean) = new Traversal[Map[K, V], V] { def modifyF[F[_]: Applicative](f: V => F[V])(s: Map[K, V]): F[Map[K, V]] = s.toList.traverse{ case (k, v) => - (if(predicate(k)) f(v) else v.pure[F]).strengthL(k) + (if(predicate(k)) f(v) else v.pure[F]).tupleLeft(k) }.map(_.toMap) } } @@ -72,22 +74,9 @@ object FilterIndex extends FilterIndexFunctions { fromTraverse(_.zipWithIndex) /************************************************************************************************/ - /** Scalaz instances */ + /** Cats instances */ /************************************************************************************************/ - import scalaz.{==>>, IList, NonEmptyList, Order} - - implicit def iListFilterIndex[A]: FilterIndex[IList[A], Int, A] = - fromTraverse(_.zipWithIndex) - - implicit def iMapFilterIndex[K: Order, V]: FilterIndex[K ==>> V, K, V] = new FilterIndex[K ==>> V, K, V] { - import scalaz.syntax.applicative._ - def filterIndex(predicate: K => Boolean) = new Traversal[K ==>> V, V] { - def modifyF[F[_]: Applicative](f: V => F[V])(s: K ==>> V): F[K ==>> V] = - s.toList.traverse{ case (k, v) => - (if(predicate(k)) f(v) else v.pure[F]).strengthL(k) - }.map(==>>.fromList(_)) - } - } + import cats.data.NonEmptyList implicit def nelFilterIndex[A]: FilterIndex[NonEmptyList[A], Int, A] = fromTraverse(_.zipWithIndex) diff --git a/core/shared/src/main/scala/monocle/function/Index.scala b/core/shared/src/main/scala/monocle/function/Index.scala index 38b535dc6..3cd55a5fe 100644 --- a/core/shared/src/main/scala/monocle/function/Index.scala +++ b/core/shared/src/main/scala/monocle/function/Index.scala @@ -4,7 +4,6 @@ import monocle.{Iso, Optional} import scala.annotation.implicitNotFound import scala.util.Try -import scalaz.Id._ /** * Typeclass that defines an [[Optional]] from an `S` to an `A` at an index `I` @@ -40,7 +39,6 @@ object Index extends IndexFunctions{ /************************************************************************************************/ /** Std instances */ /************************************************************************************************/ - import scalaz.syntax.traverse._ implicit def listIndex[A]: Index[List[A], Int, A] = new Index[List[A], Int, A] { def index(i: Int) = Optional[List[A], A]( @@ -70,28 +68,16 @@ object Index extends IndexFunctions{ } /************************************************************************************************/ - /** Scalaz instances */ + /** Cats instances */ /************************************************************************************************/ import monocle.function.Cons1.{oneAndCons1, nelCons1} - import scalaz.{==>>, IList, Order, NonEmptyList, OneAnd} - - implicit def iListIndex[A]: Index[IList[A], Int, A] = new Index[IList[A], Int, A] { - def index(i: Int) = Optional[IList[A], A]( - il => if(i < 0) None else il.drop(i).headOption)( - a => il => il.zipWithIndex.traverse[Id, A]{ - case (_ , index) if index == i => a - case (value, index) => value - } - ) - } - - implicit def iMapIndex[K: Order, V]: Index[K ==>> V, K, V] = fromAt + import cats.data.{NonEmptyList, OneAnd} implicit def nelIndex[A]: Index[NonEmptyList[A], Int, A] = new Index[NonEmptyList[A], Int, A] { def index(i: Int): Optional[NonEmptyList[A], A] = i match { case 0 => nelCons1.head.asOptional - case _ => nelCons1.tail composeOptional iListIndex.index(i-1) + case _ => nelCons1.tail composeOptional listIndex.index(i-1) } } diff --git a/core/shared/src/main/scala/monocle/function/Plated.scala b/core/shared/src/main/scala/monocle/function/Plated.scala index 27b5a306b..f60b3ab31 100644 --- a/core/shared/src/main/scala/monocle/function/Plated.scala +++ b/core/shared/src/main/scala/monocle/function/Plated.scala @@ -3,10 +3,11 @@ package monocle.function import monocle.{Setter, Traversal} import scala.annotation.implicitNotFound -import scalaz.std.stream._ -import scalaz.std.anyVal._ -import scalaz.syntax.monad._ -import scalaz.{Applicative, Monad, State, Traverse} +import cats.{Applicative, Monad, Traverse} +import cats.data.State +import cats.instances.int._ +import cats.instances.stream._ +import cats.syntax.flatMap._ /** * [[Plated]] is a type-class for types which can extract their immediate @@ -67,8 +68,8 @@ trait PlatedFunctions { def transformCounting[A: Plated](f: A => Option[A])(a: A): (Int, A) = { transformM[A, State[Int, ?]] { b => f(b).map(c => State((i: Int) => (i + 1, c))) - .getOrElse(State.state(b)) - }(a).runZero + .getOrElse(State.pure(b)) + }(a).runEmpty.value } @@ -128,14 +129,15 @@ object Plated extends PlatedFunctions { } /************************************************************************************************/ - /** Scalaz instances */ + /** Cats instances */ /************************************************************************************************/ - import scalaz.{Cofree, Free, IList, ICons, INil, Tree} + import cats.Now + import cats.free.{Cofree, Free} implicit def cofreePlated[S[_]: Traverse, A]: Plated[Cofree[S, A]] = new Plated[Cofree[S, A]] { val plate: Traversal[Cofree[S, A], Cofree[S, A]] = new Traversal[Cofree[S, A], Cofree[S, A]] { def modifyF[F[_]: Applicative](f: Cofree[S, A] => F[Cofree[S, A]])(s: Cofree[S, A]): F[Cofree[S, A]] = - Applicative[F].map(Traverse[S].traverse(s.t.run)(f))(Cofree(s.head, _)) + Applicative[F].map(Traverse[S].traverse(s.tail.value)(f))(t => Cofree(s.head, Now(t))) } } @@ -148,21 +150,4 @@ object Plated extends PlatedFunctions { ) } } - - implicit def ilistPlated[A]: Plated[IList[A]] = new Plated[IList[A]] { - val plate: Traversal[IList[A], IList[A]] = new Traversal[IList[A], IList[A]] { - def modifyF[F[_]: Applicative](f: IList[A] => F[IList[A]])(s: IList[A]): F[IList[A]] = - s match { - case ICons(x, xs) => Applicative[F].map(f(xs))(x :: _) - case INil() => Applicative[F].pure(INil()) - } - } - } - - implicit def treePlated[A]: Plated[Tree[A]] = new Plated[Tree[A]] { - val plate: Traversal[Tree[A], Tree[A]] = new Traversal[Tree[A], Tree[A]] { - def modifyF[F[_]: Applicative](f: Tree[A] => F[Tree[A]])(s: Tree[A]): F[Tree[A]] = - Applicative[F].map(Traverse[Stream].traverse(s.subForest)(f))(Tree.Node(s.rootLabel, _)) - } - } } diff --git a/core/shared/src/main/scala/monocle/function/Possible.scala b/core/shared/src/main/scala/monocle/function/Possible.scala index 723b3d27d..2f72f4bbb 100644 --- a/core/shared/src/main/scala/monocle/function/Possible.scala +++ b/core/shared/src/main/scala/monocle/function/Possible.scala @@ -3,7 +3,7 @@ package monocle.function import monocle.{Iso, Optional} import scala.util.Try -import scalaz.{Maybe, Validation, \/} +import cats.data.{Validated => Validation} /** * Typeclass that defines an [[Optional]] from a monomorphic container `S` to a possible value `A`. @@ -40,16 +40,6 @@ object Possible extends PossibleFunctions { def possible = monocle.std.either.stdRight.asOptional } - implicit def maybePossible[A,B]: Possible[Maybe[A], A] = - new Possible[Maybe[A], A] { - def possible = monocle.std.maybe.just.asOptional - } - - implicit def disjunctionPossible[A,B]: Possible[A \/ B, B] = - new Possible[A \/ B, B] { - def possible = monocle.std.disjunction.right.asOptional - } - implicit def validationPossible[A,B]: Possible[Validation[A,B], B] = new Possible[Validation[A,B], B] { def possible = monocle.std.validation.success.asOptional diff --git a/core/shared/src/main/scala/monocle/function/Reverse.scala b/core/shared/src/main/scala/monocle/function/Reverse.scala index dc51bb47d..23e9a29d9 100644 --- a/core/shared/src/main/scala/monocle/function/Reverse.scala +++ b/core/shared/src/main/scala/monocle/function/Reverse.scala @@ -66,18 +66,10 @@ object Reverse extends ReverseFunctions { fromReverseFunction(_.reverse) /************************************************************************************************/ - /** Scalaz instances */ + /** Cats instances */ /************************************************************************************************/ - import scalaz.{IList, NonEmptyList, Tree} - - implicit def iListReverse[A]: Reverse[IList[A], IList[A]] = - fromReverseFunction(_.reverse) + import cats.data.NonEmptyList implicit def nelReverse[A]: Reverse[NonEmptyList[A], NonEmptyList[A]] = fromReverseFunction(_.reverse) - - implicit def treeReverse[A]: Reverse[Tree[A], Tree[A]] = new Reverse[Tree[A], Tree[A]] { - val reverse = Iso[Tree[A], Tree[A]](reverseTree)(reverseTree) - private def reverseTree(tree: Tree[A]): Tree[A] = Tree.Node(tree.rootLabel, tree.subForest.reverse.map(reverseTree)) - } -} \ No newline at end of file +} diff --git a/core/shared/src/main/scala/monocle/function/Snoc.scala b/core/shared/src/main/scala/monocle/function/Snoc.scala index 340a82911..6583b7195 100644 --- a/core/shared/src/main/scala/monocle/function/Snoc.scala +++ b/core/shared/src/main/scala/monocle/function/Snoc.scala @@ -4,7 +4,10 @@ import monocle.function.fields._ import monocle.{Iso, Optional, Prism} import scala.annotation.implicitNotFound -import scalaz.{Applicative, \/} +import cats.Applicative +import cats.instances.option._ +import cats.syntax.either._ +import scala.{Either => \/} /** * Typeclass that defines a [[Prism]] between an `S` and its init `S` and last `S` @@ -45,11 +48,10 @@ object Snoc extends SnocFunctions { /************************************************************************************************/ /** Std instances */ /************************************************************************************************/ - import scalaz.std.option._ implicit def listSnoc[A]: Snoc[List[A], A] = new Snoc[List[A], A]{ val snoc = Prism[List[A], (List[A], A)]( - s => Applicative[Option].apply2(\/.fromTryCatchNonFatal(s.init).toOption, s.lastOption)((_,_))){ + s => Applicative[Option].map2(\/.catchNonFatal(s.init).toOption, s.lastOption)((_,_))){ case (init, last) => init :+ last } } @@ -78,16 +80,4 @@ object Snoc extends SnocFunctions { case (xs, x) => xs :+ x } } - - /************************************************************************************************/ - /** Scalaz instances */ - /************************************************************************************************/ - import scalaz.IList - - implicit def iListSnoc[A]: Snoc[IList[A], A] = new Snoc[IList[A], A]{ - val snoc = Prism[IList[A], (IList[A], A)]( - il => Applicative[Option].apply2(il.initOption, il.lastOption)((_,_))){ - case (init, last) => init :+ last - } - } -} \ No newline at end of file +} diff --git a/core/shared/src/main/scala/monocle/function/Snoc1.scala b/core/shared/src/main/scala/monocle/function/Snoc1.scala index e962db457..d12964e0a 100644 --- a/core/shared/src/main/scala/monocle/function/Snoc1.scala +++ b/core/shared/src/main/scala/monocle/function/Snoc1.scala @@ -64,12 +64,13 @@ object Snoc1 extends Snoc1Functions { } /************************************************************************************************/ - /** Scalaz instances */ + /** Cats instances */ /************************************************************************************************/ - import scalaz.{IList, NonEmptyList} + import cats.data.NonEmptyList + import scala.{List => IList} implicit def nelSnoc1[A]:Snoc1[NonEmptyList[A], IList[A], A] = new Snoc1[NonEmptyList[A], IList[A], A]{ val snoc1: Iso[NonEmptyList[A], (IList[A], A)] = - Iso((nel:NonEmptyList[A]) => nel.init -> nel.last){case (i,l) => NonEmptyList.nel(l, i.reverse).reverse} + Iso((nel:NonEmptyList[A]) => nel.init -> nel.last){case (i,l) => NonEmptyList(l, i.reverse).reverse} } -} \ No newline at end of file +} diff --git a/core/shared/src/main/scala/monocle/function/Wrapped.scala b/core/shared/src/main/scala/monocle/function/Wrapped.scala index 39083afb8..396278b45 100644 --- a/core/shared/src/main/scala/monocle/function/Wrapped.scala +++ b/core/shared/src/main/scala/monocle/function/Wrapped.scala @@ -2,29 +2,13 @@ package monocle.function import monocle.Iso -import scala.annotation.implicitNotFound - -/** - * Typeclass that defines an [[Iso]] from an `S` to an `A` where `S` is expected to wrap `A`. - * @tparam S source of [[Iso]] - * @tparam A target of [[Iso]], `A` is supposed to be unique for a given `S` - */ -@implicitNotFound("Could not find an instance of Wrapped[${S},${A}], please check Monocle instance location policy to " + - "find out which import is necessary") -abstract class Wrapped[S, A] extends Serializable { - def wrapped: Iso[S, A] -} +import newts._ trait WrappedFunctions { - def wrapped[S, A](implicit ev: Wrapped[S, A]): Iso[S, A] = ev.wrapped - def unwrapped[S, A](implicit ev: Wrapped[S, A]): Iso[A, S] = ev.wrapped.reverse -} + def wrapped[S](implicit ev: Newtype[S]): Iso[S, ev.A] = + Iso[S, ev.A](ev.unwrap(_))(ev.wrap) -object Wrapped extends WrappedFunctions { - import scalaz.{@@, Tag} + def unwrapped[S](implicit ev: Newtype[S]): Iso[ev.A, S] = wrapped.reverse +} - implicit def tagWrapped[A, B]: Wrapped[A @@ B, A] = new Wrapped[A @@ B, A] { - val wrapped: Iso[A @@ B, A] = - Iso(Tag.unwrap[A, B])(Tag.apply) - } -} \ No newline at end of file +object Wrapped extends WrappedFunctions diff --git a/core/shared/src/main/scala/monocle/internal/Bounded.scala b/core/shared/src/main/scala/monocle/internal/Bounded.scala index 178105240..6890cb756 100644 --- a/core/shared/src/main/scala/monocle/internal/Bounded.scala +++ b/core/shared/src/main/scala/monocle/internal/Bounded.scala @@ -2,8 +2,8 @@ package monocle.internal import monocle.Prism -import scalaz.syntax.order._ -import scalaz.Order +import cats.syntax.order._ +import cats.Order private[monocle] trait Bounded[T] { def MinValue: T diff --git a/core/shared/src/main/scala/monocle/law/IsoLaws.scala b/core/shared/src/main/scala/monocle/law/IsoLaws.scala index 06727990b..3f58c47b1 100644 --- a/core/shared/src/main/scala/monocle/law/IsoLaws.scala +++ b/core/shared/src/main/scala/monocle/law/IsoLaws.scala @@ -3,8 +3,8 @@ package monocle.law import monocle.Iso import monocle.internal.IsEq -import scalaz.Const -import scalaz.Id._ +import cats.data.Const +import cats.Id case class IsoLaws[S, A](iso: Iso[S, A]) { @@ -26,7 +26,7 @@ case class IsoLaws[S, A](iso: Iso[S, A]) { iso.set(a)(s) <==> iso.modify(_ => a)(s) def consistentModifyModifyId(s: S, f: A => A): IsEq[S] = - iso.modify(f)(s) <==> iso.modifyF(a => id.pure(f(a)))(s) + iso.modify(f)(s) <==> iso.modifyF[Id](f)(s) def consistentGetModifyId(s: S): IsEq[A] = iso.get(s) <==> iso.modifyF[Const[A, ?]](Const(_))(s).getConst diff --git a/core/shared/src/main/scala/monocle/law/LensLaws.scala b/core/shared/src/main/scala/monocle/law/LensLaws.scala index 6d32f9c47..bcbc1cca4 100644 --- a/core/shared/src/main/scala/monocle/law/LensLaws.scala +++ b/core/shared/src/main/scala/monocle/law/LensLaws.scala @@ -3,8 +3,8 @@ package monocle.law import monocle.Lens import monocle.internal.IsEq -import scalaz.Const -import scalaz.Id._ +import cats.data.Const +import cats.Id case class LensLaws[S, A](lens: Lens[S, A]) { import IsEq.syntax @@ -28,7 +28,7 @@ case class LensLaws[S, A](lens: Lens[S, A]) { lens.set(a)(s) <==> lens.modify(_ => a)(s) def consistentModifyModifyId(s: S, f: A => A): IsEq[S] = - lens.modify(f)(s) <==> lens.modifyF(a => id.pure(f(a)))(s) + lens.modify(f)(s) <==> lens.modifyF[Id](f)(s) def consistentGetModifyId(s: S): IsEq[A] = lens.get(s) <==> lens.modifyF[Const[A, ?]](Const(_))(s).getConst diff --git a/core/shared/src/main/scala/monocle/law/OptionalLaws.scala b/core/shared/src/main/scala/monocle/law/OptionalLaws.scala index 57bbd8912..bfe314b24 100644 --- a/core/shared/src/main/scala/monocle/law/OptionalLaws.scala +++ b/core/shared/src/main/scala/monocle/law/OptionalLaws.scala @@ -3,12 +3,10 @@ package monocle.law import monocle.Optional import monocle.internal.IsEq -import scalaz.Id._ -import scalaz.Tags.First -import scalaz.std.option._ -import scalaz.syntax.std.option._ -import scalaz.syntax.tag._ -import scalaz.{@@, Const} +import cats.Id +import cats.data.Const +import newts.FirstOption +import newts.syntax.all._ case class OptionalLaws[S, A](optional: Optional[S, A]) { import IsEq.syntax @@ -32,8 +30,8 @@ case class OptionalLaws[S, A](optional: Optional[S, A]) { optional.set(a)(s) <==> optional.modify(_ => a)(s) def consistentModifyModifyId(s: S, f: A => A): IsEq[S] = - optional.modify(f)(s) <==> optional.modifyF(a => id.pure(f(a)))(s) + optional.modify(f)(s) <==> optional.modifyF[Id](f)(s) def consistentGetOptionModifyId(s: S): IsEq[Option[A]] = - optional.getOption(s) <==> optional.modifyF[Const[Option[A] @@ First, ?]](a => Const(Some(a).first))(s).getConst.unwrap + optional.getOption(s) <==> optional.modifyF[Const[FirstOption[A], ?]](a => Const(Some(a).asFirstOption))(s).getConst.unwrap } diff --git a/core/shared/src/main/scala/monocle/law/PrismLaws.scala b/core/shared/src/main/scala/monocle/law/PrismLaws.scala index f8abb8bc1..ec5aa4a85 100644 --- a/core/shared/src/main/scala/monocle/law/PrismLaws.scala +++ b/core/shared/src/main/scala/monocle/law/PrismLaws.scala @@ -3,12 +3,10 @@ package monocle.law import monocle.Prism import monocle.internal.IsEq -import scalaz.Id._ -import scalaz.Tags.First -import scalaz.std.option._ -import scalaz.syntax.std.option._ -import scalaz.syntax.tag._ -import scalaz.{@@, Const} +import cats.Id +import cats.data.Const +import newts.FirstOption +import newts.syntax.all._ case class PrismLaws[S, A](prism: Prism[S, A]) { import IsEq.syntax @@ -29,8 +27,8 @@ case class PrismLaws[S, A](prism: Prism[S, A]) { prism.set(a)(s) <==> prism.modify(_ => a)(s) def consistentModifyModifyId(s: S, f: A => A): IsEq[S] = - prism.modify(f)(s) <==> prism.modifyF(a => id.pure(f(a)))(s) + prism.modify(f)(s) <==> prism.modifyF[Id](f)(s) def consistentGetOptionModifyId(s: S): IsEq[Option[A]] = - prism.getOption(s) <==> prism.modifyF[Const[Option[A] @@ First, ?]](a => Const(Some(a).first))(s).getConst.unwrap + prism.getOption(s) <==> prism.modifyF[Const[FirstOption[A], ?]](a => Const(Some(a).asFirstOption))(s).getConst.unwrap } diff --git a/core/shared/src/main/scala/monocle/std/All.scala b/core/shared/src/main/scala/monocle/std/All.scala index d80b63210..40acb5fa3 100644 --- a/core/shared/src/main/scala/monocle/std/All.scala +++ b/core/shared/src/main/scala/monocle/std/All.scala @@ -14,18 +14,12 @@ trait StdInstances with ListOptics with LongOptics with MapOptics - with MaybeOptics with OptionOptics with StringOptics with Tuple1Optics with TryOptics - // Scalaz Instances + // Cats Instances with CofreeOptics - with Either3Optics - with DisjunctionOptics with TheseOptics - with IListInstances - with IMapOptics with NonEmptyListOptics - with TreeOptics with ValidationOptics diff --git a/core/shared/src/main/scala/monocle/std/Byte.scala b/core/shared/src/main/scala/monocle/std/Byte.scala index 70bcf0206..6ad6d1d53 100644 --- a/core/shared/src/main/scala/monocle/std/Byte.scala +++ b/core/shared/src/main/scala/monocle/std/Byte.scala @@ -3,7 +3,7 @@ package monocle.std import monocle.Prism import monocle.internal.Bounded -import scalaz.std.anyVal._ +import cats.instances.byte._ object byte extends ByteOptics diff --git a/core/shared/src/main/scala/monocle/std/Char.scala b/core/shared/src/main/scala/monocle/std/Char.scala index de503a2c4..1c0276e61 100644 --- a/core/shared/src/main/scala/monocle/std/Char.scala +++ b/core/shared/src/main/scala/monocle/std/Char.scala @@ -3,7 +3,7 @@ package monocle.std import monocle.Prism import monocle.internal.Bounded -import scalaz.std.anyVal.{char => charInstances} +import cats.instances.char._ object char extends CharOptics diff --git a/core/shared/src/main/scala/monocle/std/Cofree.scala b/core/shared/src/main/scala/monocle/std/Cofree.scala index 166e39b3d..274cc4473 100644 --- a/core/shared/src/main/scala/monocle/std/Cofree.scala +++ b/core/shared/src/main/scala/monocle/std/Cofree.scala @@ -2,8 +2,9 @@ package monocle.std import monocle.{Iso, PIso} -import scalaz.Tree.Node -import scalaz.{Cofree, OneAnd, Tree} +import cats.{Later, Now} +import cats.data.OneAnd +import cats.free.Cofree object cofree extends CofreeOptics @@ -13,34 +14,18 @@ trait CofreeOptics { def pCofreeToStream[A, B]: PIso[Cofree[Option, A], Cofree[Option, B], OneAnd[Stream, A], OneAnd[Stream, B]] = PIso[Cofree[Option, A], Cofree[Option, B], OneAnd[Stream, A], OneAnd[Stream, B]]( - (c: Cofree[Option, A]) => OneAnd[Stream, A](c.head, toStream(c.tail)) + (c: Cofree[Option, A]) => OneAnd[Stream, A](c.head, toStream(c.tail.value)) ){ case OneAnd(head, tail) => fromStream(head, tail) } /** [[Iso]] variant of [[pCofreeToStream]] */ def cofreeToStream[A]: Iso[Cofree[Option, A], OneAnd[Stream, A]] = pCofreeToStream[A, A] - - private def toTree[A](c: Cofree[Stream, A]): Tree[A] = - Node(c.head, c.tail.map(toTree[A])) - - private def fromTree[A](c: Tree[A]): Cofree[Stream, A] = - Cofree.delay(c.rootLabel, c.subForest.map(fromTree[A])) - - /** Polymorphic isomorphism between `Cofree[Stream, _]` and `Tree` */ - def pCofreeToTree[A, B]: PIso[Cofree[Stream, A], Cofree[Stream, B], - Tree[A], Tree[B]] = - PIso[Cofree[Stream, A], Cofree[Stream, B], Tree[A], Tree[B]](toTree[A])(fromTree[B]) - - /** [[Iso]] variant of [[pCofreeToTree]] */ - def cofreeToTree[A]: Iso[Cofree[Stream, A], Tree[A]] = - pCofreeToTree[A, A] - private def toStream[A](optC: Option[Cofree[Option, A]]): Stream[A] = - optC.fold(Stream.empty[A])(c => c.head #:: toStream(c.tail)) + optC.fold(Stream.empty[A])(c => c.head #:: toStream(c.tail.value)) private def fromStream[A, B](z: A, c: Stream[A]): Cofree[Option, A] = c match { - case head #:: tail => Cofree.delay(z, Some(fromStream(head, tail))) - case _ => Cofree(z, None: Option[Cofree[Option, A]]) + case head #:: tail => Cofree(z, Later(Some(fromStream(head, tail)))) + case _ => Cofree(z, Now(None: Option[Cofree[Option, A]])) } } diff --git a/core/shared/src/main/scala/monocle/std/Disjunction.scala b/core/shared/src/main/scala/monocle/std/Disjunction.scala deleted file mode 100644 index aca8fd4dc..000000000 --- a/core/shared/src/main/scala/monocle/std/Disjunction.scala +++ /dev/null @@ -1,33 +0,0 @@ -package monocle.std - -import scalaz.{Validation, \/-, -\/, \/} -import monocle.{Iso, PIso, Prism, PPrism} - -object disjunction extends DisjunctionOptics - -trait DisjunctionOptics { - - final def pLeft[A, B, C]: PPrism[A \/ B, C \/ B, A, C] = - PPrism[A \/ B, C \/ B, A, C](_.swap.bimap(\/-.apply, identity))(-\/.apply) - - final def left[A, B]: Prism[A \/ B, A] = - pLeft[A, B, A] - - final def pRight[A, B, C]: PPrism[A \/ B, A \/ C, B, C] = - PPrism[A \/ B, A \/ C, B, C](_.bimap(-\/.apply, identity))(\/-.apply) - - final def right[A, B]: Prism[A \/ B, B] = - pRight[A, B, B] - - final def pDisjunctionToValidation[E1, E2, A1, A2]: PIso[E1 \/ A1, E2 \/ A2, Validation[E1, A1], Validation[E2, A2]] = - validation.pValidationToDisjunction[E2, E1, A2, A1].reverse - - final def disjunctionToValidation[E, A]: Iso[E \/ A, Validation[E, A]] = - pDisjunctionToValidation[E, E, A, A] - - final def pDisjunctionToEither[E1, E2, A1, A2]: PIso[E1 \/ A1, E2 \/ A2, Either[E1, A1], Either[E2, A2]] = - PIso[E1 \/ A1, E2 \/ A2, Either[E1, A1], Either[E2, A2]](_.toEither)(_.fold(\/.left, \/.right)) - - final def disjunctionToEither[E, A]: Iso[E \/ A, Either[E, A]] = - pDisjunctionToEither[E, E, A, A] -} diff --git a/core/shared/src/main/scala/monocle/std/Either.scala b/core/shared/src/main/scala/monocle/std/Either.scala index 60bd2b554..33d30dc7c 100644 --- a/core/shared/src/main/scala/monocle/std/Either.scala +++ b/core/shared/src/main/scala/monocle/std/Either.scala @@ -1,7 +1,7 @@ package monocle.std -import monocle.{Prism, PPrism, Iso, PIso} -import scalaz.{\/, -\/, \/-} +import monocle.{Prism, PPrism} +import scala.{Left => -\/, Right => \/-} object either extends EitherOptics @@ -24,10 +24,4 @@ trait EitherOptics { final def stdRight[A, B]: Prism[Either[A, B], B] = pStdRight[A, B, B] - - final def pEitherToDisjunction[E1, E2, A1, A2]: PIso[Either[E1, A1], Either[E2, A2], E1 \/ A1, E2 \/ A2] = - disjunction.pDisjunctionToEither[E2, E1, A2, A1].reverse - - final def eitherToDisjunction[E, A]: Iso[Either[E, A], E \/ A] = - pEitherToDisjunction[E, E, A, A] } diff --git a/core/shared/src/main/scala/monocle/std/Either3.scala b/core/shared/src/main/scala/monocle/std/Either3.scala deleted file mode 100644 index bfc2c860d..000000000 --- a/core/shared/src/main/scala/monocle/std/Either3.scala +++ /dev/null @@ -1,40 +0,0 @@ -package monocle.std - -import monocle.{Prism, PPrism} -import scalaz.{Either3, Left3, Middle3, Right3} -import scalaz.{-\/, \/-} - -object either3 extends Either3Optics - -trait Either3Optics { - - final def pLeft3[A, B, C, D]: PPrism[Either3[A, B, C], Either3[D, B, C], A, D] = - PPrism[Either3[A, B, C], Either3[D, B, C], A, D] { - case Left3(a) => \/-(a) - case Middle3(b) => -\/(Middle3(b)) - case Right3(c) => -\/(Right3(c)) - }(Left3.apply) - - final def left3[A, B, C]: Prism[Either3[A, B, C], A] = - pLeft3[A, B, C, A] - - final def pMiddle3[A, B, C, D]: PPrism[Either3[A, B, C], Either3[A, D, C], B, D] = - PPrism[Either3[A, B, C], Either3[A, D, C], B, D] { - case Left3(a) => -\/(Left3(a)) - case Middle3(b) => \/-(b) - case Right3(c) => -\/(Right3(c)) - }(Middle3.apply) - - final def middle3[A, B, C]: Prism[Either3[A, B, C], B] = - pMiddle3[A, B, C, B] - - final def pRight3[A, B, C, D]: PPrism[Either3[A, B, C], Either3[A, B, D], C, D] = - PPrism[Either3[A, B, C], Either3[A, B, D], C, D] { - case Left3(a) => -\/(Left3(a)) - case Middle3(b) => -\/(Middle3(b)) - case Right3(c) => \/-(c) - }(Right3.apply) - - final def right3[A, B, C]: Prism[Either3[A, B, C], C] = - pRight3[A, B, C, C] -} diff --git a/core/shared/src/main/scala/monocle/std/IList.scala b/core/shared/src/main/scala/monocle/std/IList.scala deleted file mode 100644 index 633a6f2ea..000000000 --- a/core/shared/src/main/scala/monocle/std/IList.scala +++ /dev/null @@ -1,15 +0,0 @@ -package monocle.std - -import monocle.{Iso, PIso} - -import scalaz.IList - -object ilist extends IListInstances - -trait IListInstances { - final def pIListToList[A, B]: PIso[IList[A], IList[B], List[A], List[B]] = - PIso[IList[A], IList[B], List[A], List[B]](_.toList)(IList.fromList) - - final def iListToList[A]: Iso[IList[A], List[A]] = - pIListToList[A, A] -} diff --git a/core/shared/src/main/scala/monocle/std/IMap.scala b/core/shared/src/main/scala/monocle/std/IMap.scala deleted file mode 100644 index 8cefbd50f..000000000 --- a/core/shared/src/main/scala/monocle/std/IMap.scala +++ /dev/null @@ -1,5 +0,0 @@ -package monocle.std - -object imap extends IMapOptics - -trait IMapOptics diff --git a/core/shared/src/main/scala/monocle/std/Int.scala b/core/shared/src/main/scala/monocle/std/Int.scala index 75c02ab5e..431f91c00 100644 --- a/core/shared/src/main/scala/monocle/std/Int.scala +++ b/core/shared/src/main/scala/monocle/std/Int.scala @@ -3,7 +3,7 @@ package monocle.std import monocle.Prism import monocle.internal.Bounded -import scalaz.std.anyVal._ +import cats.instances.int._ object int extends IntOptics diff --git a/core/shared/src/main/scala/monocle/std/Long.scala b/core/shared/src/main/scala/monocle/std/Long.scala index 12f4b64c6..30c10fb46 100644 --- a/core/shared/src/main/scala/monocle/std/Long.scala +++ b/core/shared/src/main/scala/monocle/std/Long.scala @@ -3,7 +3,7 @@ package monocle.std import monocle.Prism import monocle.internal.Bounded -import scalaz.std.anyVal._ +import cats.instances.long._ object long extends LongOptics diff --git a/core/shared/src/main/scala/monocle/std/Maybe.scala b/core/shared/src/main/scala/monocle/std/Maybe.scala deleted file mode 100644 index 023af66fe..000000000 --- a/core/shared/src/main/scala/monocle/std/Maybe.scala +++ /dev/null @@ -1,25 +0,0 @@ -package monocle.std - -import monocle.{Iso, PIso, PPrism, Prism} - -import scalaz.syntax.std.option._ -import scalaz.{-\/, Maybe, \/-} - -object maybe extends MaybeOptics - -trait MaybeOptics { - final def pMaybeToOption[A, B]: PIso[Maybe[A], Maybe[B], Option[A], Option[B]] = - PIso((_: Maybe[A]).toOption)((_: Option[B]).toMaybe) - - final def maybeToOption[A]: Iso[Maybe[A], Option[A]] = - pMaybeToOption[A, A] - - final def pJust[A, B]: PPrism[Maybe[A], Maybe[B], A, B] = - PPrism[Maybe[A], Maybe[B], A, B](_.cata(\/-(_), -\/(Maybe.empty)))(Maybe.just[B]) - - final def just[A]: Prism[Maybe[A], A] = - pJust[A, A] - - final def nothing[A]: Prism[Maybe[A], Unit] = - Prism[Maybe[A], Unit](m => if(m.isEmpty) Some(()) else None)(_ => Maybe.empty) -} \ No newline at end of file diff --git a/core/shared/src/main/scala/monocle/std/NonEmptyList.scala b/core/shared/src/main/scala/monocle/std/NonEmptyList.scala index 747265c7e..ef687d674 100644 --- a/core/shared/src/main/scala/monocle/std/NonEmptyList.scala +++ b/core/shared/src/main/scala/monocle/std/NonEmptyList.scala @@ -2,7 +2,8 @@ package monocle.std import monocle.{Iso, PIso} -import scalaz.{ICons, IList, INil, NonEmptyList, OneAnd} +import cats.data.{NonEmptyList, OneAnd} +import scala.{:: => ICons, List => IList, Nil => INil} object nel extends NonEmptyListOptics @@ -10,16 +11,16 @@ trait NonEmptyListOptics { final def pNelToOneAnd[A, B]: PIso[NonEmptyList[A], NonEmptyList[B], OneAnd[List,A], OneAnd[List,B]] = PIso((nel: NonEmptyList[A]) => OneAnd[List,A](nel.head, nel.tail.toList))( - (oneAnd: OneAnd[List, B]) => NonEmptyList.nel(oneAnd.head, IList.fromList(oneAnd.tail))) + (oneAnd: OneAnd[List, B]) => NonEmptyList(oneAnd.head, oneAnd.tail)) final def nelToOneAnd[A]: Iso[NonEmptyList[A], OneAnd[List,A]] = pNelToOneAnd[A, A] final def pOptNelToList[A, B]: PIso[Option[NonEmptyList[A]], Option[NonEmptyList[B]], List[A], List[B]] = - PIso[Option[NonEmptyList[A]], Option[NonEmptyList[B]], IList[A], IList[B]](_.fold(IList.empty[A])(_.list)){ - case INil() => None - case ICons(x, xs) => Some(NonEmptyList.nel(x, xs)) - } composeIso ilist.pIListToList + PIso[Option[NonEmptyList[A]], Option[NonEmptyList[B]], IList[A], IList[B]](_.fold(IList.empty[A])(_.toList)){ + case INil => None + case ICons(x, xs) => Some(NonEmptyList(x, xs)) + } final def optNelToList[A]: Iso[Option[NonEmptyList[A]], List[A]] = pOptNelToList[A, A] diff --git a/core/shared/src/main/scala/monocle/std/Option.scala b/core/shared/src/main/scala/monocle/std/Option.scala index 6dadb9b34..4bc980b6a 100644 --- a/core/shared/src/main/scala/monocle/std/Option.scala +++ b/core/shared/src/main/scala/monocle/std/Option.scala @@ -2,7 +2,7 @@ package monocle.std import monocle.{Iso, PIso, PPrism, Prism} -import scalaz.{-\/, \/, \/-} +import scala.{Left => -\/, Either => \/, Right => \/-} object option extends OptionOptics @@ -17,7 +17,7 @@ trait OptionOptics { Prism[Option[A], Unit]{ case None => Some(()); case Some(_) => None }(_ => None) final def pOptionToDisjunction[A, B]: PIso[Option[A], Option[B], Unit \/ A, Unit \/ B] = - PIso[Option[A], Option[B], Unit \/ A, Unit \/ B](_.map(\/-(_)) getOrElse -\/(()))(_.toOption) + PIso[Option[A], Option[B], Unit \/ A, Unit \/ B](_.map(\/-(_)) getOrElse -\/(()))(_.right.toOption) final def optionToDisjunction[A]: Iso[Option[A], Unit \/ A] = pOptionToDisjunction[A, A] diff --git a/core/shared/src/main/scala/monocle/std/String.scala b/core/shared/src/main/scala/monocle/std/String.scala index 3ebb34c1b..fdc40678b 100644 --- a/core/shared/src/main/scala/monocle/std/String.scala +++ b/core/shared/src/main/scala/monocle/std/String.scala @@ -6,9 +6,9 @@ import java.util.UUID import monocle.{Iso, Prism} import scala.util.Try -import scalaz.std.list._ -import scalaz.std.option._ -import scalaz.syntax.traverse._ +import cats.instances.list._ +import cats.instances.option._ +import cats.syntax.traverse._ object string extends StringOptics @@ -51,7 +51,7 @@ trait StringOptics extends PlatformSpecificStringOptics { private def parseLongUnsigned(s: List[Char]): Option[Long] = if(s.isEmpty) None - else s.traverse(charToDigit).map(_.foldl(0L)(n => d => n * 10 + d)) + else s.traverse(charToDigit).map(_.foldLeft(0L)((n, d) => n * 10 + d)) private def charToDigit(c: Char): Option[Int] = if (c >= '0' && c <= '9') Some(c - '0') diff --git a/core/shared/src/main/scala/monocle/std/These.scala b/core/shared/src/main/scala/monocle/std/These.scala index 35bd91750..704c04f2a 100644 --- a/core/shared/src/main/scala/monocle/std/These.scala +++ b/core/shared/src/main/scala/monocle/std/These.scala @@ -2,16 +2,17 @@ package monocle.std import monocle.Prism -import scalaz.\&/.{Both, That, This} -import scalaz.syntax.either._ -import scalaz.{-\/, \&/, \/, \/-} +import cats.data.Ior.{Both, Right => That, Left => This} +import cats.data.{Ior => \&/} +import cats.syntax.either._ +import scala.{Left => -\/, Either => \/, Right => \/-} object these extends TheseOptics trait TheseOptics { def theseToDisjunction[A, B]: Prism[A \&/ B, A \/ B] = Prism[A \&/ B, A \/ B]{ - case This(a) => Some(a.left[B]) - case That(b) => Some(b.right[A]) + case This(a) => Some(a.asLeft[B]) + case That(b) => Some(b.asRight[A]) case Both(_, _) => None }{ case -\/(a) => This(a) diff --git a/core/shared/src/main/scala/monocle/std/Tree.scala b/core/shared/src/main/scala/monocle/std/Tree.scala deleted file mode 100644 index 415ef3ec5..000000000 --- a/core/shared/src/main/scala/monocle/std/Tree.scala +++ /dev/null @@ -1,51 +0,0 @@ -package monocle.std - -import monocle.Lens -import monocle.function.all._ - -import scala.annotation.tailrec -import scala.collection.immutable.Stream.Empty -import scalaz.Tree -import scalaz.Tree.{Leaf, Node} - -object tree extends TreeOptics - -trait TreeOptics { - - final def rootLabel[A]: Lens[Tree[A], A] = - Lens[Tree[A], A](_.rootLabel)(l => tree => Node(l, tree.subForest)) - - final def subForest[A]: Lens[Tree[A], Stream[Tree[A]]] = - Lens[Tree[A], Stream[Tree[A]]](_.subForest)(children => tree => Node(tree.rootLabel, children)) - - final def leftMostLabel[A]: Lens[Tree[A], A] = { - @tailrec - def _get(tree: Tree[A]): A = tree.subForest match { - case Empty => tree.rootLabel - case x #:: xs => _get(x) - } - - def _set(newLeaf: A)(tree: Tree[A]): Tree[A] = tree.subForest match { - case Empty => Leaf(newLeaf) - case xs => Node(tree.rootLabel, headOption[Stream[Tree[A]], Tree[A]].modify(_set(newLeaf))(xs) ) - } - - Lens(_get)(_set) - } - - final def rightMostLabel[A]: Lens[Tree[A], A] = { - @tailrec - def _get(tree: Tree[A]): A = tree.subForest match { - case Empty => tree.rootLabel - case xs => _get(xs.last) - } - - def _set(newLeaf: A)(tree: Tree[A]): Tree[A] = tree.subForest match { - case Empty => Leaf(newLeaf) - case xs => Node(tree.rootLabel, lastOption[Stream[Tree[A]], Tree[A]].modify(_set(newLeaf))(xs) ) - } - - Lens(_get)(_set) - } - -} diff --git a/core/shared/src/main/scala/monocle/std/Try.scala b/core/shared/src/main/scala/monocle/std/Try.scala index ebb7e0049..0f8c190c6 100644 --- a/core/shared/src/main/scala/monocle/std/Try.scala +++ b/core/shared/src/main/scala/monocle/std/Try.scala @@ -4,7 +4,7 @@ import monocle.{Prism, PPrism} import scala.util.{Try, Success, Failure} -import scalaz.{-\/, \/-} +import scala.{Left => -\/, Right => \/-} object utilTry extends TryOptics diff --git a/core/shared/src/main/scala/monocle/std/Validation.scala b/core/shared/src/main/scala/monocle/std/Validation.scala index b539d1864..ea2520d20 100644 --- a/core/shared/src/main/scala/monocle/std/Validation.scala +++ b/core/shared/src/main/scala/monocle/std/Validation.scala @@ -2,31 +2,32 @@ package monocle.std import monocle.{Prism, Iso, PIso, PPrism} -import scalaz.syntax.either._ -import scalaz.syntax.validation._ -import scalaz.{Validation, \/} +import cats.data.{Validated => Validation} +import cats.syntax.either._ +import cats.syntax.validated._ +import scala.{Either => \/} object validation extends ValidationOptics trait ValidationOptics { final def pSuccess[E, A, B]: PPrism[Validation[E, A], Validation[E, B], A, B] = PPrism[Validation[E, A], Validation[E, B], A, B]( - _.fold(e => Validation.failure[E, B](e).left[A], a => a.right[Validation[E, B]]) - )(_.success[E]) + _.fold(e => Validation.invalid[E, B](e).asLeft[A], a => a.asRight[Validation[E, B]]) + )(_.valid[E]) final def success[E, A]: Prism[Validation[E, A], A] = pSuccess[E, A, A] final def pFailure[E, A, F]: PPrism[Validation[E, A], Validation[F, A], E, F] = PPrism[Validation[E, A], Validation[F, A], E, F]( - _.fold(e => e.right[Validation[F, A]], a => Validation.success[F, A](a).left[E]) - )(_.failure[A]) + _.fold(e => e.asRight[Validation[F, A]], a => Validation.valid[F, A](a).asLeft[E]) + )(_.invalid[A]) final def failure[E, A]: Prism[Validation[E, A], E] = pFailure[E, A, E] final def pValidationToDisjunction[E1, E2, A1, A2]: PIso[Validation[E1, A1], Validation[E2, A2], E1 \/ A1, E2 \/ A2] = - PIso[Validation[E1, A1], Validation[E2, A2], E1 \/ A1, E2 \/ A2](_.disjunction)(_.validation) + PIso[Validation[E1, A1], Validation[E2, A2], E1 \/ A1, E2 \/ A2](_.toEither)(_.toValidated) final def validationToDisjunction[E, A]: Iso[Validation[E, A], E \/ A] = pValidationToDisjunction[E, E, A, A] diff --git a/core/shared/src/main/scala/monocle/syntax/All.scala b/core/shared/src/main/scala/monocle/syntax/All.scala index ea112623e..9a1260dd9 100644 --- a/core/shared/src/main/scala/monocle/syntax/All.scala +++ b/core/shared/src/main/scala/monocle/syntax/All.scala @@ -2,4 +2,4 @@ package monocle.syntax object all extends Syntaxes -trait Syntaxes extends ApplySyntax with TraversalSyntax +trait Syntaxes extends ApplySyntax diff --git a/core/shared/src/main/scala/monocle/syntax/Apply.scala b/core/shared/src/main/scala/monocle/syntax/Apply.scala index 724f30512..366bb5cf3 100644 --- a/core/shared/src/main/scala/monocle/syntax/Apply.scala +++ b/core/shared/src/main/scala/monocle/syntax/Apply.scala @@ -2,7 +2,7 @@ package monocle.syntax import monocle._ -import scalaz.{Applicative, Functor, Monoid} +import cats.{Applicative, Functor, Monoid} object apply extends ApplySyntax diff --git a/core/shared/src/main/scala/monocle/syntax/Traversal.scala b/core/shared/src/main/scala/monocle/syntax/Traversal.scala deleted file mode 100644 index ddb324b47..000000000 --- a/core/shared/src/main/scala/monocle/syntax/Traversal.scala +++ /dev/null @@ -1,112 +0,0 @@ -package monocle.syntax - -import scalaz.{IndexedStore, FreeAp} - -object traversal extends TraversalSyntax - -trait TraversalSyntax { - implicit def toTraversalBuilder[A, B, T](a: A): TraversalBuilder[A, B, T] = - new TraversalBuilder[A, B, T] { val a1 = a } -} - -trait TraversalBuilder[A, B, T] { - val a1: A - - def apply(f: B => T) = - ap(a1, pt(f)) - - def ~(_a2: A) = new TraversalBuilder2 { val a2 = _a2 } - - trait TraversalBuilder2 { - val a2: A - - def apply(f: (B, B) => T) = - ap(a2, ap(a1, pt(f.curried))) - - def ~(_a3: A) = new TraversalBuilder3 { val a3 = _a3 } - - trait TraversalBuilder3 { - val a3: A - - def apply(f: (B, B, B) => T) = - ap(a3, ap(a2, ap(a1, pt(f.curried)))) - - def ~(_a4: A) = new TraversalBuilder4 { val a4 = _a4 } - - trait TraversalBuilder4 { - val a4: A - - def apply(f: (B, B, B, B) => T) = - ap(a4, ap(a3, ap(a2, ap(a1, pt(f.curried))))) - - def ~(_a5: A) = new TraversalBuilder5 { val a5 = _a5 } - - trait TraversalBuilder5 { - val a5: A - - def apply(f: (B, B, B, B, B) => T) = - ap(a5, ap(a4, ap(a3, ap(a2, ap(a1, pt(f.curried)))))) - - def ~(_a6: A) = new TraversalBuilder6 { val a6 = _a6 } - - trait TraversalBuilder6 { - val a6: A - - def apply(f: (B, B, B, B, B, B) => T) = - ap(a6, ap(a5, ap(a4, ap(a3, ap(a2, ap(a1, pt(f.curried))))))) - - def ~(_a7: A) = new TraversalBuilder7 { val a7 = _a7 } - - trait TraversalBuilder7 { - val a7: A - - def apply(f: (B, B, B, B, B, B, B) => T) = - ap(a7, ap(a6, ap(a5, ap(a4, ap(a3, ap(a2, ap(a1, pt(f.curried)))))))) - - def ~(_a8: A) = new TraversalBuilder8 { val a8 = _a8 } - - trait TraversalBuilder8 { - val a8: A - - def apply(f: (B, B, B, B, B, B, B, B) => T) = - ap(a8, ap(a7, ap(a6, ap(a5, ap(a4, ap(a3, ap(a2, ap(a1, pt(f.curried))))))))) - - def ~(_a9: A) = new TraversalBuilder9 { val a9 = _a9 } - - trait TraversalBuilder9 { - val a9: A - - def apply(f: (B, B, B, B, B, B, B, B, B) => T) = - ap(a9, ap(a8, ap(a7, ap(a6, ap(a5, ap(a4, ap(a3, ap(a2, ap(a1, pt(f.curried)))))))))) - - def ~(_a10: A) = new TraversalBuilder10 { val a10 = _a10 } - - trait TraversalBuilder10 { - val a10: A - - def apply(f: (B, B, B, B, B, B, B, B, B, B) => T) = - ap(a10, ap(a9, ap(a8, ap(a7, ap(a6, ap(a5, ap(a4, ap(a3, ap(a2, ap(a1, pt(f.curried))))))))))) - - def ~(_a11: A) = new TraversalBuilder11 { val a11 = _a11 } - - trait TraversalBuilder11 { - val a11: A - - def apply(f: (B, B, B, B, B, B, B, B, B, B, B) => T) = - ap(a11, ap(a10, ap(a9, ap(a8, ap(a7, ap(a6, ap(a5, ap(a4, ap(a3, ap(a2, ap(a1, pt(f.curried)))))))))))) - } - } - } - } - } - } - } - } - } - } - - private def pt[X](x: X) = FreeAp.pure[IndexedStore[A, B, ?], X](x) - - private def ap[X](h: A, x: => FreeAp[IndexedStore[A, B, ?], B => X]) = - FreeAp[IndexedStore[A, B, ?], B, X](IndexedStore(identity, h), x) -} diff --git a/docs/src/main/tut/modules.md b/docs/src/main/tut/modules.md index 53bb32b82..b4486a3e9 100644 --- a/docs/src/main/tut/modules.md +++ b/docs/src/main/tut/modules.md @@ -10,7 +10,7 @@ position: 1 In an attempt to be modular, Monocle is broken up into several modules: * *core* - contains optics (e.g. `Lens`, `Prism`, `Traversal`) and type class definitions (e.g. `Index`, `Each`, `Plated`) and - type class instances for standard library types and scalaz data types + type class instances for standard library types and cats data types * *macro* - macros to simplify the generation of optics * *laws* - laws for the optics and type classes * *generic* - optics and type class instances for `HList` and `Coproduct` from [shapeless](https://github.com/milessabin/shapeless) @@ -41,4 +41,4 @@ libraryDependencies ++= Seq( ) ``` -You need to replace `${version}` with the version of Monocle you want to use. \ No newline at end of file +You need to replace `${version}` with the version of Monocle you want to use. diff --git a/docs/src/main/tut/optics/lens.md b/docs/src/main/tut/optics/lens.md index cce39c6e2..0b8ffc964 100644 --- a/docs/src/main/tut/optics/lens.md +++ b/docs/src/main/tut/optics/lens.md @@ -59,13 +59,13 @@ val n = streetNumber.get(address) streetNumber.set(n + 1)(address) ``` -We can push the idea even further, with `modifyF` we can update the target of a `Lens` in a context, cf `scalaz.Functor`: +We can push the idea even further, with `modifyF` we can update the target of a `Lens` in a context, cf `cats.Functor`: ```tut:silent def neighbors(n: Int): List[Int] = if(n > 0) List(n - 1, n + 1) else List(n + 1) -import scalaz.std.list._ // to get Functor[List] instance +import cats.syntax.list._ // to get Functor[List] instance ``` ```tut @@ -77,7 +77,7 @@ This would work with any kind of `Functor` and is especially useful in conjuncti where one has the task to update a deeply nested structure with the result of an asynchronous computation: ```tut:silent -import scalaz.std.scalaFuture._ +import cats.instances.scalaFuture._ import scala.concurrent._ import scala.concurrent.ExecutionContext.Implicits._ // to get global ExecutionContext diff --git a/docs/src/main/tut/optics/traversal.md b/docs/src/main/tut/optics/traversal.md index 4c8c107be..66da1ec4b 100644 --- a/docs/src/main/tut/optics/traversal.md +++ b/docs/src/main/tut/optics/traversal.md @@ -11,11 +11,11 @@ A `Traversal` is the generalisation of an `Optional` to several targets. In othe to focus from a type `S` into 0 to n values of type `A`. The most common example of a `Traversal` would be to focus into all elements inside of a container (e.g. `List`, `Vector`, `Option`). -To do this we will use the relation between the typeclass `scalaz.Traverse` and `Traversal`: +To do this we will use the relation between the typeclass `cats.Traverse` and `Traversal`: ```tut:silent import monocle.Traversal -import scalaz.std.list._ // to get the Traverse instance for List +import cats.syntax.list._ // to get the Traverse instance for List val xs = List(1,2,3,4,5) ``` @@ -55,10 +55,10 @@ For example, let's write a `Traversal` for `Map` that will focus into all values ```tut:silent import monocle.Traversal -import scalaz.Applicative -import scalaz.std.map._ -import scalaz.syntax.traverse._ -import scalaz.syntax.applicative._ +import cats.Applicative +import cats.instances.map._ +import cats.syntax.traverse._ +import cats.syntax.applicative._ def filterKey[K, V](predicate: K => Boolean): Traversal[Map[K, V], V] = new Traversal[Map[K, V], V]{ diff --git a/example/src/test/scala/monocle/JsonExample.scala b/example/src/test/scala/monocle/JsonExample.scala index b76d3fc0b..dd15a3259 100644 --- a/example/src/test/scala/monocle/JsonExample.scala +++ b/example/src/test/scala/monocle/JsonExample.scala @@ -145,17 +145,17 @@ class JsonExample extends MonocleSuite { } implicit val jsonPlated: Plated[Json] = new Plated[Json] { - import scalaz.Applicative - import scalaz.std.list._ - import scalaz.std.map._ - import scalaz.syntax.traverse._ + import cats.Applicative + import cats.Traverse + import cats.syntax.functor._ + import cats.syntax.traverse._ val plate: Traversal[Json, Json] = new Traversal[Json, Json] { def modifyF[F[_]: Applicative](f: Json => F[Json])(a: Json): F[Json] = a match { case j@(JsString(_) | JsNumber(_)) => Applicative[F].pure(j) case JsArray(l) => l.traverse(f).map(JsArray) - case JsObject(m) => m.traverse(f).map(JsObject) + case JsObject(m) => Traverse[Map[String, ?]].traverse(m)(f).map(JsObject) } } } diff --git a/example/src/test/scala/monocle/function/AtExample.scala b/example/src/test/scala/monocle/function/AtExample.scala index fbc3c1ad4..133fd9328 100644 --- a/example/src/test/scala/monocle/function/AtExample.scala +++ b/example/src/test/scala/monocle/function/AtExample.scala @@ -5,8 +5,7 @@ import monocle.refined._ import shapeless.test.illTyped import eu.timepit.refined.auto._ -import scalaz.IMap -import scalaz.std.string._ +import scala.collection.immutable.{Map => IMap} class AtExample extends MonocleSuite { diff --git a/example/src/test/scala/monocle/function/EachExample.scala b/example/src/test/scala/monocle/function/EachExample.scala index 27a8674df..b4fab1980 100644 --- a/example/src/test/scala/monocle/function/EachExample.scala +++ b/example/src/test/scala/monocle/function/EachExample.scala @@ -2,9 +2,8 @@ package monocle.function import monocle.MonocleSuite -import scalaz.Tree._ -import scalaz.std.string._ -import scalaz.{IList, IMap, OneAnd} +import scala.collection.immutable.{List => IList, Map => IMap} +import cats.data.OneAnd class EachExample extends MonocleSuite { @@ -32,9 +31,4 @@ class EachExample extends MonocleSuite { ((1, 2, 3, 4, 5, 6) applyTraversal each modify( _ + 1)) shouldEqual ((2, 3, 4, 5, 6, 7)) } - test("Each can be used on Tree") { - Node(1, Stream(Leaf(2), Leaf(3))) applyTraversal each modify( _ + 1) shouldEqual Node(2, Stream(Leaf(3), Leaf(4))) - (Node(1, Stream(Leaf(2), Leaf(3))) applyTraversal each getAll) shouldEqual List(1,2,3) - } - } diff --git a/example/src/test/scala/monocle/function/EmptyExample.scala b/example/src/test/scala/monocle/function/EmptyExample.scala index 90a80f073..4efef999d 100644 --- a/example/src/test/scala/monocle/function/EmptyExample.scala +++ b/example/src/test/scala/monocle/function/EmptyExample.scala @@ -3,8 +3,6 @@ package monocle.function import monocle.MonocleSuite import monocle.function.all.{empty => mempty} -import scalaz.{==>>, IMap} - class EmptyExample extends MonocleSuite { test("empty is a Prism that is successful only when S is empty") { @@ -18,7 +16,6 @@ class EmptyExample extends MonocleSuite { test("_empty return the empty value of a given type") { _empty[List[Int]] shouldEqual List.empty[Int] _empty[Map[Int, String]] shouldEqual Map.empty[Int, String] - _empty[Int ==>> String] shouldEqual IMap.empty[Int, String] _empty[String] shouldEqual "" } diff --git a/example/src/test/scala/monocle/function/FilterIndexExample.scala b/example/src/test/scala/monocle/function/FilterIndexExample.scala index 68e40e0d3..7cdc9741e 100644 --- a/example/src/test/scala/monocle/function/FilterIndexExample.scala +++ b/example/src/test/scala/monocle/function/FilterIndexExample.scala @@ -2,8 +2,7 @@ package monocle.function import monocle.MonocleSuite -import scalaz.std.string._ -import scalaz.{IList, IMap} +import scala.collection.immutable.{List => IList, Map => IMap} class FilterIndexExample extends MonocleSuite { diff --git a/example/src/test/scala/monocle/function/HeadExample.scala b/example/src/test/scala/monocle/function/HeadExample.scala index bd8b710b9..7b259c48d 100644 --- a/example/src/test/scala/monocle/function/HeadExample.scala +++ b/example/src/test/scala/monocle/function/HeadExample.scala @@ -2,7 +2,7 @@ package monocle.function import monocle.MonocleSuite -import scalaz.OneAnd +import cats.data.OneAnd class HeadExample extends MonocleSuite { diff --git a/example/src/test/scala/monocle/function/HeadOptionExample.scala b/example/src/test/scala/monocle/function/HeadOptionExample.scala index f4cd4d6ce..5b801ba20 100644 --- a/example/src/test/scala/monocle/function/HeadOptionExample.scala +++ b/example/src/test/scala/monocle/function/HeadOptionExample.scala @@ -2,7 +2,7 @@ package monocle.function import monocle.MonocleSuite -import scalaz.IList +import scala.collection.immutable.{List => IList} class HeadOptionExample extends MonocleSuite { diff --git a/example/src/test/scala/monocle/function/IndexExample.scala b/example/src/test/scala/monocle/function/IndexExample.scala index 7f47bcb19..b24c3afd5 100644 --- a/example/src/test/scala/monocle/function/IndexExample.scala +++ b/example/src/test/scala/monocle/function/IndexExample.scala @@ -2,8 +2,8 @@ package monocle.function import monocle.MonocleSuite -import scalaz.std.string._ -import scalaz.{IMap, OneAnd} +import scala.collection.immutable.{Map => IMap} +import cats.data.OneAnd class IndexExample extends MonocleSuite { diff --git a/example/src/test/scala/monocle/function/InitOptionExample.scala b/example/src/test/scala/monocle/function/InitOptionExample.scala index 45bb531e1..c3a35e0a4 100644 --- a/example/src/test/scala/monocle/function/InitOptionExample.scala +++ b/example/src/test/scala/monocle/function/InitOptionExample.scala @@ -2,7 +2,7 @@ package monocle.function import monocle.MonocleSuite -import scalaz.IList +import scala.collection.immutable.{List => IList} class InitOptionExample extends MonocleSuite { diff --git a/example/src/test/scala/monocle/function/LastOptionExample.scala b/example/src/test/scala/monocle/function/LastOptionExample.scala index 9230e1660..3fe9ea3d3 100644 --- a/example/src/test/scala/monocle/function/LastOptionExample.scala +++ b/example/src/test/scala/monocle/function/LastOptionExample.scala @@ -2,7 +2,7 @@ package monocle.function import monocle.MonocleSuite -import scalaz.IList +import scala.collection.immutable.{List => IList} class LastOptionExample extends MonocleSuite { diff --git a/example/src/test/scala/monocle/function/ReverseExample.scala b/example/src/test/scala/monocle/function/ReverseExample.scala index 030d6e590..72fb2e2e1 100644 --- a/example/src/test/scala/monocle/function/ReverseExample.scala +++ b/example/src/test/scala/monocle/function/ReverseExample.scala @@ -2,8 +2,6 @@ package monocle.function import monocle._ -import scalaz.Tree._ - class ReverseExample extends MonocleSuite { test("reverse creates an Iso from a List to its reversed version") { @@ -27,10 +25,6 @@ class ReverseExample extends MonocleSuite { ("Hello" applyIso reverse get) shouldEqual "olleH" } - test("reverse creates an Iso from a Tree to its reversed version") { - (Node(1, Stream(Leaf(2), Leaf(3))) applyIso reverse get) shouldEqual Node(1, Stream(Leaf(3), Leaf(2))) - } - test("reverse creates an Iso from a Vector to its reversed version") { (Vector(1,2,3) applyIso reverse get) shouldEqual Vector(3,2,1) } diff --git a/example/src/test/scala/monocle/function/TailExample.scala b/example/src/test/scala/monocle/function/TailExample.scala index 6439ee0c6..22ed28ce6 100644 --- a/example/src/test/scala/monocle/function/TailExample.scala +++ b/example/src/test/scala/monocle/function/TailExample.scala @@ -2,7 +2,7 @@ package monocle.function import monocle.MonocleSuite -import scalaz.OneAnd +import cats.data.OneAnd class TailExample extends MonocleSuite { @@ -17,4 +17,4 @@ class TailExample extends MonocleSuite { (OneAnd(1, List(2, 3)) applyLens tail get) shouldEqual List(2, 3) } -} \ No newline at end of file +} diff --git a/example/src/test/scala/monocle/function/TailOptionExample.scala b/example/src/test/scala/monocle/function/TailOptionExample.scala index 6197bc195..2bcb070d8 100644 --- a/example/src/test/scala/monocle/function/TailOptionExample.scala +++ b/example/src/test/scala/monocle/function/TailOptionExample.scala @@ -2,7 +2,7 @@ package monocle.function import monocle.MonocleSuite -import scalaz.IList +import scala.{List => IList} class TailOptionExample extends MonocleSuite { diff --git a/example/src/test/scala/monocle/function/WrappedExample.scala b/example/src/test/scala/monocle/function/WrappedExample.scala index 85d76549e..7660e0865 100644 --- a/example/src/test/scala/monocle/function/WrappedExample.scala +++ b/example/src/test/scala/monocle/function/WrappedExample.scala @@ -2,17 +2,16 @@ package monocle.function import monocle.MonocleSuite -import scalaz.Tags -import scalaz.std.anyVal._ +import newts.{Dual, Max} class WrappedExample extends MonocleSuite { test("wrapped is an Iso") { - (Tags.Max(100) applyIso wrapped get) shouldEqual 100 + (Max(100) applyIso wrapped get) shouldEqual 100 } test("unwrapped is an Iso") { - ("Hello" applyIso unwrapped get) shouldEqual Tags.Dual("Hello") + ("Hello" applyIso unwrapped[Dual[String]] get) shouldEqual Dual("Hello") } } diff --git a/example/src/test/scala/monocle/state/StateExample.scala b/example/src/test/scala/monocle/state/StateExample.scala index 90b0d0e05..d460939be 100644 --- a/example/src/test/scala/monocle/state/StateExample.scala +++ b/example/src/test/scala/monocle/state/StateExample.scala @@ -1,6 +1,6 @@ package monocle.state -import monocle.{MonocleSuite, Optional, Setter, Getter} +import monocle.{MonocleSuite, Optional, Getter} import monocle.macros.GenLens class StateExample extends MonocleSuite { @@ -14,7 +14,7 @@ class StateExample extends MonocleSuite { i <- _age extract } yield i - getAge.run(p) shouldEqual ((Person("John", 30), 30)) + getAge.run(p).value shouldEqual ((Person("John", 30), 30)) } test("extracts"){ @@ -22,51 +22,7 @@ class StateExample extends MonocleSuite { i <- _age extracts (_ * 2) } yield i - getDoubleAge.run(p) shouldEqual ((Person("John", 30), 60)) - } - - test("mod"){ - val increment = for { - i <- _age mod (_ + 1) - } yield i - - increment.run(p) shouldEqual ((Person("John", 31), 31)) - } - - test("modo"){ - val increment = for { - i <- _age modo (_ + 1) - } yield i - - increment.run(p) shouldEqual ((Person("John", 31), 30)) - } - - test("mod_"){ - val increment = _age mod_ (_ + 1) - - increment.run(p) shouldEqual ((Person("John", 31), ())) - } - - test("assign"){ - val set20 = for { - i <- _age assign 20 - } yield i - - set20.run(p) shouldEqual ((Person("John", 20), 20)) - } - - test("assigno"){ - val set20 = for { - i <- _age assigno 20 - } yield i - - set20.run(p) shouldEqual ((Person("John", 20), 30)) - } - - test("assign_"){ - val set20 = _age assign_ 20 - - set20.run(p) shouldEqual ((Person("John", 20), ())) + getDoubleAge.run(p).value shouldEqual ((Person("John", 30), 60)) } val _oldAge = Optional[Person, Int](p => if (p.age > 50) Some(p.age) else None){ a => _.copy(age = a) } @@ -76,162 +32,28 @@ class StateExample extends MonocleSuite { val youngPerson = Person("John", 30) val update = _oldAge extract - update.run(youngPerson) shouldEqual ((Person("John", 30), None)) + update.run(youngPerson).value shouldEqual ((Person("John", 30), None)) } test("extract for Optional (predicate is true)"){ val oldPerson = Person("John", 100) val update = _oldAge extract - update.run(oldPerson) shouldEqual ((Person("John", 100), Some(100))) + update.run(oldPerson).value shouldEqual ((Person("John", 100), Some(100))) } test("extracts for Optional (predicate is false)"){ val youngPerson = Person("John", 30) val update = _oldAge extracts (_ * 2) - update.run(youngPerson) shouldEqual ((Person("John", 30), None)) + update.run(youngPerson).value shouldEqual ((Person("John", 30), None)) } test("extracts for Optional (predicate is true)"){ val oldPerson = Person("John", 100) val update = _oldAge extracts (_ * 2) - update.run(oldPerson) shouldEqual ((Person("John", 100), Some(200))) - } - - test("mod for Optional (predicate is false)"){ - val youngPerson = Person("John", 30) - val update = for { - i <- _oldAge mod (_ + 1) - } yield i - - update.run(youngPerson) shouldEqual ((Person("John", 30), None)) - } - - test("mod for Optional (predicate is true)"){ - val oldPerson = Person("John", 100) - val update = for { - i <- _oldAge mod (_ + 1) - } yield i - - update.run(oldPerson) shouldEqual ((Person("John", 101), Some(101))) - } - - test("modo for Optional (predicate is false)"){ - val youngPerson = Person("John", 30) - val update = for { - i <- _oldAge modo (_ + 1) - } yield i - - update.run(youngPerson) shouldEqual ((Person("John", 30), None)) - } - - test("modo for Optional (predicate is true)"){ - val oldPerson = Person("John", 100) - val update = for { - i <- _oldAge modo (_ + 1) - } yield i - - update.run(oldPerson) shouldEqual ((Person("John", 101), Some(100))) - } - - test("modo for Optional (chaining modifications)"){ - val oldCoolPerson = Person("Chris", 100) - val update = for { - _ <- _oldAge modo (_ + 1) - x <- _coolGuy modo (_.toLowerCase) - } yield x - - update.run(oldCoolPerson) shouldEqual ((Person("chris", 101), Some("Chris"))) - } - - test("modo for Optional (only some of the modifications are applied)"){ - val oldCoolPerson = Person("Chris", 30) - val update = for { - _ <- _oldAge modo (_ + 1) - x <- _coolGuy modo (_.toLowerCase) - } yield x - - update.run(oldCoolPerson) shouldEqual ((Person("chris", 30), Some("Chris"))) - } - - test("mod_ for Optional (predicate is false)"){ - val youngPerson = Person("John", 30) - val update = _oldAge mod_ (_ + 1) - - update.run(youngPerson) shouldEqual ((Person("John", 30), ())) - } - - test("mod_ for Optional (predicate is true)"){ - val oldPerson = Person("John", 100) - val update = _oldAge mod_ (_ + 1) - - update.run(oldPerson) shouldEqual ((Person("John", 101), ())) - } - - test("assign for Optional (predicate is true)"){ - val oldPerson = Person("John", 100) - val update = for { - i <- _oldAge assign 30 - } yield i - - update.run(oldPerson) shouldEqual ((Person("John", 30), Some(30))) - } - - test("assign for Optional (predicate is false)"){ - val youngPerson = Person("John", 30) - val update = for { - i <- _oldAge assign 100 - } yield i - - update.run(youngPerson) shouldEqual ((Person("John", 30), None)) - } - - test("assigno for Optional (predicate is true)"){ - val oldPerson = Person("John", 100) - val update = for { - i <- _oldAge assigno 30 - } yield i - - update.run(oldPerson) shouldEqual ((Person("John", 30), Some(100))) - } - - test("assigno for Optional (predicate is false)"){ - val youngPerson = Person("John", 30) - val update = for { - i <- _oldAge assigno 100 - } yield i - - update.run(youngPerson) shouldEqual ((Person("John", 30), None)) - } - - test("assign_ for Optional (predicate is true)"){ - val oldPerson = Person("John", 100) - val update = _oldAge assign_ 30 - - update.run(oldPerson) shouldEqual ((Person("John", 30),())) - } - - test("assign_ for Optional (predicate is false)"){ - val youngPerson = Person("John", 30) - val update = _oldAge assign_ 100 - - update.run(youngPerson) shouldEqual ((Person("John", 30), ())) - } - - val _nameSet = Setter[Person, String](f => p => p.copy(name = f(p.name))) - - test("mod_ for Setter"){ - val toUpper = _nameSet mod_ (_.toUpperCase) - - toUpper.run(p) shouldEqual ((Person("JOHN", 30), ())) - } - - test("assign_ for Setter"){ - val toUpper = _nameSet assign_ ("Juan") - - toUpper.run(p) shouldEqual ((Person("Juan", 30), ())) + update.run(oldPerson).value shouldEqual ((Person("John", 100), Some(200))) } val _nameGet = Getter[Person, String](_.name) @@ -239,12 +61,12 @@ class StateExample extends MonocleSuite { test("extract for Getter"){ val name = _nameGet extract - name.run(p) shouldEqual ((Person("John", 30), "John")) + name.run(p).value shouldEqual ((Person("John", 30), "John")) } test("extracts for Getter"){ val upper = _nameGet extracts (_.toUpperCase) - upper.run(p) shouldEqual ((Person("John", 30), "JOHN")) + upper.run(p).value shouldEqual ((Person("John", 30), "JOHN")) } } diff --git a/example/src/test/scala/monocle/std/TheseExample.scala b/example/src/test/scala/monocle/std/TheseExample.scala index 7a10bf6f7..a2db627a6 100644 --- a/example/src/test/scala/monocle/std/TheseExample.scala +++ b/example/src/test/scala/monocle/std/TheseExample.scala @@ -2,14 +2,15 @@ package monocle.std import monocle.MonocleSuite -import scalaz.\&/._ -import scalaz._ -import scalaz.syntax.either._ +import cats.data.{Ior => \&/} +import cats.data.Ior.{Left => This, Right => That, Both} +import cats.syntax.either._ +import scala.{Either => \/, Left => -\/, Right => \/-} class TheseExample extends MonocleSuite { test("theseToDisjunction is a prism between These and a Disjunction") { - theseToDisjunction.getOption(This(5) : Int \&/ String) shouldEqual Some(5.left[String]) - theseToDisjunction.getOption(That("Hello") : Int \&/ String) shouldEqual Some("Hello".right[Int]) + theseToDisjunction.getOption(This(5) : Int \&/ String) shouldEqual Some(5.asLeft[String]) + theseToDisjunction.getOption(That("Hello") : Int \&/ String) shouldEqual Some("Hello".asRight[Int]) theseToDisjunction.getOption(Both(5,"Hello"): Int \&/ String) shouldEqual None theseToDisjunction.reverseGet(-\/(5) : Int \/ String) shouldEqual (This(5) : Int \&/ String) diff --git a/example/src/test/scala/monocle/std/TreeExample.scala b/example/src/test/scala/monocle/std/TreeExample.scala deleted file mode 100644 index 6deea2fab..000000000 --- a/example/src/test/scala/monocle/std/TreeExample.scala +++ /dev/null @@ -1,53 +0,0 @@ -package monocle.std - -import monocle.MonocleSuite - -import scalaz.Tree._ -import scalaz.Tree - -class TreeExample extends MonocleSuite { - - // 1 - // / \ - // 2 3 - val tree = Node(1, Stream(Leaf(2), Leaf(3))) - - test("label creates a Lens from a Tree to its root label") { - (tree applyLens rootLabel get) shouldEqual 1 - - (tree applyLens rootLabel modify (_ - 1)) shouldEqual Node(0, Stream(Leaf(2), Leaf(3))) - } - - test("subForest creates a Lens from a Tree to its children") { - (Leaf(1) applyLens subForest get) shouldEqual Stream.Empty - (tree applyLens subForest get) shouldEqual Stream(Leaf(2), Leaf(3)) - - (tree applyLens rootLabel modify (_ - 1)) shouldEqual (Node(0, Stream(Leaf(2), Leaf(3)))) - } - - test("leftMostLeaf creates a Lens from a Tree to its left most Leaf") { - (Leaf(1) applyLens leftMostLabel get) shouldEqual 1 - (tree applyLens leftMostLabel get) shouldEqual 2 - - (tree applyLens leftMostLabel set 0) shouldEqual Node(1, Stream(Leaf(0), Leaf(3))) - } - - test("leftMostLeaf creates a Lens from a Tree to its right most Leaf") { - (Leaf(1) applyLens rightMostLabel get) shouldEqual 1 - (tree applyLens rightMostLabel get) shouldEqual 3 - - (tree applyLens rightMostLabel set 0) shouldEqual Node(1, Stream(Leaf(2), Leaf(0))) - } - - test("Plated universe gives us a stream of all Node") { - universe(tree) shouldEqual Stream(tree, Leaf(2), Leaf(3)) - } - - test("transformCounting on Tree counts number of changed nodes") { - transformCounting[Tree[Int]] { - case l@Leaf(3) => Some(l.map(_ + 1)) - case _ => None - }(tree) shouldEqual ((1, Node(1, Stream(Leaf(2), Leaf(4))))) - } - -} diff --git a/example/src/test/scala/monocle/std/ValidationExample.scala b/example/src/test/scala/monocle/std/ValidationExample.scala index fd8e8abc9..ce557d0e0 100644 --- a/example/src/test/scala/monocle/std/ValidationExample.scala +++ b/example/src/test/scala/monocle/std/ValidationExample.scala @@ -3,18 +3,18 @@ package monocle.std import monocle.MonocleSuite import monocle.std.{validation => mValidation} -import scalaz.syntax.validation._ +import cats.syntax.validated._ class ValidationExample extends MonocleSuite { test("success defines a Prism that can get or set the underlying value of a Success instance") { - mValidation.success.getOption(123.success) shouldEqual Some(123) - mValidation.success.getOption("abc".failure) shouldEqual None + mValidation.success.getOption(123.valid) shouldEqual Some(123) + mValidation.success.getOption("abc".invalid) shouldEqual None - mValidation.success.set(555)(123.success) shouldEqual 555.success - mValidation.success.set(123)("abc".failure) shouldEqual "abc".failure + mValidation.success.set(555)(123.valid) shouldEqual 555.valid + mValidation.success.set(123)("abc".invalid) shouldEqual "abc".invalid } test("failure defines a Prism that can modify the underlying value of a Failure instance") { - mValidation.failure[String, Int].modify(_.reverse)("abc".failure) shouldEqual "cba".failure + mValidation.failure[String, Int].modify(_.reverse)("abc".invalid) shouldEqual "cba".invalid } } diff --git a/example/src/test/scala/monocle/syntax/SymbolicSyntaxExample.scala b/example/src/test/scala/monocle/syntax/SymbolicSyntaxExample.scala index 547af5136..36ef55d54 100644 --- a/example/src/test/scala/monocle/syntax/SymbolicSyntaxExample.scala +++ b/example/src/test/scala/monocle/syntax/SymbolicSyntaxExample.scala @@ -25,8 +25,8 @@ class SymbolicSyntaxExample extends MonocleSuite { (myStore &|-> _articles ^|-? headOption ^<-? _sofa ^|-> _color getOption) - (_articles ^<-> iListToList.reverse ^|->> each ^<-? _sofa ^|-> _price).modify(_ / 2)(myStore) === - (myStore &|-> _articles ^<-> iListToList.reverse ^|->> each ^<-? _sofa ^|-> _price modify(_ / 2)) + (_articles ^<-> reverse ^|->> each ^<-? _sofa ^|-> _price).modify(_ / 2)(myStore) === + (myStore &|-> _articles ^<-> reverse ^|->> each ^<-? _sofa ^|-> _price modify(_ / 2)) (myStore.articles &|-? index(1) ^<-? _sofa getOption) shouldEqual None } diff --git a/example/src/test/scala/other/ImportExample.scala b/example/src/test/scala/other/ImportExample.scala index 8708dfa5f..5c2023f8b 100644 --- a/example/src/test/scala/other/ImportExample.scala +++ b/example/src/test/scala/other/ImportExample.scala @@ -6,7 +6,7 @@ import org.typelevel.discipline.scalatest.Discipline import shapeless.test.illTyped import shapeless.{::, HNil} -import scalaz.IList +import scala.collection.immutable.{List => IList} case class Custom(value: Int) diff --git a/generic/shared/src/main/scala/monocle/generic/Product.scala b/generic/shared/src/main/scala/monocle/generic/Product.scala index abce2a6a3..02dbd53de 100644 --- a/generic/shared/src/main/scala/monocle/generic/Product.scala +++ b/generic/shared/src/main/scala/monocle/generic/Product.scala @@ -5,8 +5,8 @@ import monocle.PTraversal import monocle.function.Each import monocle.{ Iso, Traversal } import monocle.generic.internal.TupleGeneric -import scalaz.Applicative -import scalaz.syntax.apply._ +import cats.Applicative +import cats.syntax.apply._ import shapeless.{ ::, Generic, HList, HNil } object product extends ProductOptics @@ -22,7 +22,7 @@ trait ProductOptics { implicit def hConsEach[A, Rest <: HList](implicit restEach: Each[Rest, A]) = new Each[A :: Rest, A] { def each: Traversal[A :: Rest, A] = new PTraversal[A :: Rest, A :: Rest, A, A] { def modifyF[F[_]: Applicative](f: A => F[A])(s: A :: Rest): F[A :: Rest] = - (f(s.head) |@| restEach.each.modifyF(f)(s.tail)).apply(_ :: _) + (f(s.head), restEach.each.modifyF(f)(s.tail)).mapN(_ :: _) } } diff --git a/law/shared/src/main/scala/monocle/law/discipline/IsoTests.scala b/law/shared/src/main/scala/monocle/law/discipline/IsoTests.scala index 3277f44e9..7552b6beb 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/IsoTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/IsoTests.scala @@ -6,7 +6,7 @@ import org.scalacheck.Arbitrary import org.scalacheck.Prop._ import org.typelevel.discipline.Laws -import scalaz.Equal +import cats.{Eq => Equal} object IsoTests extends Laws { @@ -23,4 +23,4 @@ object IsoTests extends Laws { ) } -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/LensTests.scala b/law/shared/src/main/scala/monocle/law/discipline/LensTests.scala index bf3e42a89..94c2647b5 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/LensTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/LensTests.scala @@ -6,7 +6,7 @@ import org.scalacheck.Arbitrary import org.scalacheck.Prop._ import org.typelevel.discipline.Laws -import scalaz.Equal +import cats.{Eq => Equal} object LensTests extends Laws { diff --git a/law/shared/src/main/scala/monocle/law/discipline/OptionalTests.scala b/law/shared/src/main/scala/monocle/law/discipline/OptionalTests.scala index 44fa262f1..93f4a10c2 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/OptionalTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/OptionalTests.scala @@ -6,8 +6,8 @@ import org.scalacheck.Arbitrary import org.scalacheck.Prop._ import org.typelevel.discipline.Laws -import scalaz.Equal -import scalaz.std.option._ +import cats.{Eq => Equal} +import cats.instances.option._ object OptionalTests extends Laws { diff --git a/law/shared/src/main/scala/monocle/law/discipline/PrismTests.scala b/law/shared/src/main/scala/monocle/law/discipline/PrismTests.scala index 836512d10..3d8e01867 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/PrismTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/PrismTests.scala @@ -6,8 +6,8 @@ import org.scalacheck.Arbitrary import org.scalacheck.Prop._ import org.typelevel.discipline.Laws -import scalaz.Equal -import scalaz.std.option._ +import cats.{Eq => Equal} +import cats.instances.option._ object PrismTests extends Laws { diff --git a/law/shared/src/main/scala/monocle/law/discipline/SetterTests.scala b/law/shared/src/main/scala/monocle/law/discipline/SetterTests.scala index 62744cda6..f4ed48e58 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/SetterTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/SetterTests.scala @@ -6,7 +6,7 @@ import org.scalacheck.Prop._ import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal +import cats.{Eq => Equal} object SetterTests extends Laws { diff --git a/law/shared/src/main/scala/monocle/law/discipline/TraversalTests.scala b/law/shared/src/main/scala/monocle/law/discipline/TraversalTests.scala index caa85605d..3f3594ef2 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/TraversalTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/TraversalTests.scala @@ -6,9 +6,9 @@ import org.scalacheck.Prop._ import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal -import scalaz.std.list._ -import scalaz.std.option._ +import cats.{Eq => Equal} +import cats.instances.list._ +import cats.instances.option._ object TraversalTests extends Laws { diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/AtTests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/AtTests.scala index b26beeecd..7ca362577 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/AtTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/AtTests.scala @@ -6,7 +6,7 @@ import monocle.law.discipline.LensTests import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal +import cats.{Eq => Equal} object AtTests extends Laws { @@ -14,4 +14,4 @@ object AtTests extends Laws { new SimpleRuleSet("At", LensTests(at(_: I)(evAt)).props: _*) } -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/Cons1Tests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/Cons1Tests.scala index 408360e0c..ec024ac57 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/Cons1Tests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/Cons1Tests.scala @@ -6,8 +6,8 @@ import monocle.law.discipline.{IsoTests, LensTests} import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal -import scalaz.std.tuple._ +import cats.{Eq => Equal} +import cats.instances.tuple._ object Cons1Tests extends Laws { @@ -17,4 +17,4 @@ object Cons1Tests extends Laws { IsoTests(cons1[S, H, T]).props ++ LensTests(head[S, H, T]).props ++ LensTests(tail[S, H, T]).props: _*) -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/ConsTests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/ConsTests.scala index 5c6618fde..776b30915 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/ConsTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/ConsTests.scala @@ -6,8 +6,8 @@ import monocle.law.discipline.{OptionalTests, PrismTests} import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal -import scalaz.std.tuple._ +import cats.{Eq => Equal} +import cats.instances.tuple._ object ConsTests extends Laws { @@ -18,4 +18,4 @@ object ConsTests extends Laws { OptionalTests(headOption[S, A]).props ++ OptionalTests(tailOption[S, A]).props: _*) -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/EachTests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/EachTests.scala index a3c6f7902..b3989834e 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/EachTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/EachTests.scala @@ -6,7 +6,7 @@ import monocle.law.discipline.TraversalTests import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal +import cats.{Eq => Equal} object EachTests extends Laws { @@ -14,4 +14,4 @@ object EachTests extends Laws { def apply[S: Equal : Arbitrary, A: Equal : Arbitrary](implicit evEach: Each[S, A], arbAA: Arbitrary[A => A]): RuleSet = new SimpleRuleSet("Each", TraversalTests(each[S, A]).props: _*) -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/EmptyTests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/EmptyTests.scala index c315dcdc3..e0f382f13 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/EmptyTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/EmptyTests.scala @@ -6,8 +6,8 @@ import monocle.law.discipline.PrismTests import org.scalacheck.{Arbitrary, Prop} import org.typelevel.discipline.Laws -import scalaz.Equal -import scalaz.std.anyVal._ +import cats.{Eq => Equal} +import cats.instances.unit._ object EmptyTests extends Laws { @@ -18,4 +18,4 @@ object EmptyTests extends Laws { override def props: Seq[(String, Prop)] = PrismTests(empty[S]).props } -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/FilterIndexTests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/FilterIndexTests.scala index 254873d3f..a32d34aa5 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/FilterIndexTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/FilterIndexTests.scala @@ -6,7 +6,7 @@ import monocle.law.discipline.TraversalTests import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal +import cats.{Eq => Equal} object FilterIndexTests extends Laws { @@ -15,4 +15,4 @@ object FilterIndexTests extends Laws { new SimpleRuleSet("FilterIndex", TraversalTests(filterIndex(_: I => Boolean)(evFilterIndex)).props: _*) -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/IndexTests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/IndexTests.scala index 5433b6336..26ec4e7d1 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/IndexTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/IndexTests.scala @@ -6,7 +6,7 @@ import monocle.law.discipline.OptionalTests import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal +import cats.{Eq => Equal} object IndexTests extends Laws { @@ -14,4 +14,4 @@ object IndexTests extends Laws { arbAA: Arbitrary[A => A]): RuleSet = new SimpleRuleSet("Index", OptionalTests(index(_ : I)(evIndex)).props: _*) -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/PossibleTests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/PossibleTests.scala index 81e97290a..01650e9ef 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/PossibleTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/PossibleTests.scala @@ -6,7 +6,7 @@ import monocle.law.discipline.OptionalTests import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal +import cats.{Eq => Equal} object PossibleTests extends Laws { diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/ReverseTests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/ReverseTests.scala index 0eed567f0..9ea5f3eed 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/ReverseTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/ReverseTests.scala @@ -6,7 +6,7 @@ import monocle.law.discipline.IsoTests import org.scalacheck.{Arbitrary, Prop} import org.typelevel.discipline.Laws -import scalaz.Equal +import cats.{Eq => Equal} object ReverseTests extends Laws { @@ -21,4 +21,4 @@ object ReverseTests extends Laws { override def props: Seq[(String, Prop)] = IsoTests(reverse[S, A]).props } -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/Snoc1Tests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/Snoc1Tests.scala index 4d2e3f713..06112c661 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/Snoc1Tests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/Snoc1Tests.scala @@ -6,8 +6,8 @@ import monocle.law.discipline.{IsoTests, LensTests} import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal -import scalaz.std.tuple._ +import cats.{Eq => Equal} +import cats.instances.tuple._ object Snoc1Tests extends Laws { @@ -18,4 +18,4 @@ object Snoc1Tests extends Laws { LensTests(init[S, I, L]).props ++ LensTests(last[S, I, L]).props: _*) -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/function/SnocTests.scala b/law/shared/src/main/scala/monocle/law/discipline/function/SnocTests.scala index bb44a8071..e4bc3e800 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/function/SnocTests.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/function/SnocTests.scala @@ -6,8 +6,8 @@ import monocle.law.discipline.{OptionalTests, PrismTests} import org.scalacheck.Arbitrary import org.typelevel.discipline.Laws -import scalaz.Equal -import scalaz.std.tuple._ +import cats.{Eq => Equal} +import cats.instances.tuple._ object SnocTests extends Laws { @@ -17,4 +17,4 @@ object SnocTests extends Laws { PrismTests(snoc[S, A]).props ++ OptionalTests(lastOption[S, A]).props ++ OptionalTests(initOption[S, A]).props: _*) -} \ No newline at end of file +} diff --git a/law/shared/src/main/scala/monocle/law/discipline/package.scala b/law/shared/src/main/scala/monocle/law/discipline/package.scala index 103bdefeb..bedde43ac 100644 --- a/law/shared/src/main/scala/monocle/law/discipline/package.scala +++ b/law/shared/src/main/scala/monocle/law/discipline/package.scala @@ -5,11 +5,11 @@ import org.scalacheck.Prop import org.scalacheck.Prop._ import org.scalacheck.util.Pretty -import scalaz.Equal +import cats.{Eq => Equal} package object discipline { implicit def isEqToProp[A](isEq: IsEq[A])(implicit A: Equal[A]): Prop = - if(A.equal(isEq.lhs, isEq.rhs)) proved else falsified :| { + if(A.eqv(isEq.lhs, isEq.rhs)) proved else falsified :| { val exp = Pretty.pretty[A](isEq.rhs, Pretty.Params(0)) val act = Pretty.pretty[A](isEq.lhs, Pretty.Params(0)) "Expected "+exp+" but got "+act diff --git a/macro/shared/src/main/scala/monocle/macros/GenPrism.scala b/macro/shared/src/main/scala/monocle/macros/GenPrism.scala index 0cb66cdfe..77a6b5886 100644 --- a/macro/shared/src/main/scala/monocle/macros/GenPrism.scala +++ b/macro/shared/src/main/scala/monocle/macros/GenPrism.scala @@ -19,7 +19,7 @@ private class GenPrismImpl(val c: blackbox.Context) { val sTpeSym = sTpe.typeSymbol.companion c.Expr[Prism[S, A]](q""" import monocle.Prism - import scalaz.{\/, \/-, -\/} + import scala.{Either => \/, Right => \/-, Left => -\/} new Prism[$sTpe, $aTpe]{ def getOrModify(s: $sTpe): $sTpe \/ $aTpe = diff --git a/macro/shared/src/main/scala/monocle/macros/internal/Macro.scala b/macro/shared/src/main/scala/monocle/macros/internal/Macro.scala index b47c98437..2ed98ce20 100644 --- a/macro/shared/src/main/scala/monocle/macros/internal/Macro.scala +++ b/macro/shared/src/main/scala/monocle/macros/internal/Macro.scala @@ -76,7 +76,7 @@ private[macros] class MacroImpl(val c: blackbox.Context) { c.Expr[PLens[S, T, A, B]](q""" import monocle.PLens - import scalaz.Functor + import cats.Functor import _root_.scala.language.higherKinds // prevent warning at call site new PLens[$sTpe, $tTpe, $aTpe, $bTpe]{ diff --git a/project/plugins.sbt b/project/plugins.sbt index a36516e6c..93d51d141 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,7 +4,7 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.1") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.14") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1") addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.25") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.16") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.19") addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.1.0") addSbtPlugin("org.scala-native" % "sbt-scalajs-crossproject" % "0.1.0") addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.2.1") diff --git a/state/shared/src/main/scala/monocle/state/All.scala b/state/shared/src/main/scala/monocle/state/All.scala index e499c6995..fb1be0199 100644 --- a/state/shared/src/main/scala/monocle/state/All.scala +++ b/state/shared/src/main/scala/monocle/state/All.scala @@ -3,5 +3,4 @@ package monocle.state object all extends StateLensSyntax with StateOptionalSyntax with StateGetterSyntax - with StateSetterSyntax with ReaderGetterSyntax diff --git a/state/shared/src/main/scala/monocle/state/ReaderGetterSyntax.scala b/state/shared/src/main/scala/monocle/state/ReaderGetterSyntax.scala index 7efe6d1c4..6e87a04b2 100644 --- a/state/shared/src/main/scala/monocle/state/ReaderGetterSyntax.scala +++ b/state/shared/src/main/scala/monocle/state/ReaderGetterSyntax.scala @@ -2,7 +2,7 @@ package monocle.state import monocle.Getter -import scalaz.{Reader} +import cats.data.Reader trait ReaderGetterSyntax { implicit def toReaderGetterOps[S, A](getter: Getter[S, A]): ReaderGetterOps[S, A] = diff --git a/state/shared/src/main/scala/monocle/state/StateGetterSyntax.scala b/state/shared/src/main/scala/monocle/state/StateGetterSyntax.scala index 75579f0fc..1d9c746be 100644 --- a/state/shared/src/main/scala/monocle/state/StateGetterSyntax.scala +++ b/state/shared/src/main/scala/monocle/state/StateGetterSyntax.scala @@ -2,7 +2,7 @@ package monocle.state import monocle.Getter -import scalaz.State +import cats.data.State trait StateGetterSyntax { implicit def toStateGetterOps[S, A](getter: Getter[S, A]): StateGetterOps[S, A] = diff --git a/state/shared/src/main/scala/monocle/state/StateLensSyntax.scala b/state/shared/src/main/scala/monocle/state/StateLensSyntax.scala index a274b3297..49a903a55 100644 --- a/state/shared/src/main/scala/monocle/state/StateLensSyntax.scala +++ b/state/shared/src/main/scala/monocle/state/StateLensSyntax.scala @@ -2,7 +2,7 @@ package monocle.state import monocle.PLens -import scalaz.{IndexedState, State} +import cats.data.State trait StateLensSyntax { implicit def toStateLensOps[S, T, A, B](lens: PLens[S, T, A, B]): StateLensOps[S, T, A, B] = @@ -25,32 +25,4 @@ final class StateLensOps[S, T, A, B](lens: PLens[S, T, A, B]) { /** extracts the value viewed through the lens and applies `f` over it */ def extracts[B](f: A => B): State[S, B] = extract.map(f) - - /** modify the value viewed through the lens and returns its *new* value */ - def mod(f: A => B): IndexedState[S, T, B] = - IndexedState(s => { - val a = lens.get(s) - val b = f(a) - (lens.set(b)(s), b) - }) - - /** modify the value viewed through the lens and returns its *old* value */ - def modo(f: A => B): IndexedState[S, T, A] = - toState.leftMap(lens.modify(f)) - - /** modify the value viewed through the lens and ignores both values */ - def mod_(f: A => B): IndexedState[S, T, Unit] = - IndexedState(s => (lens.modify(f)(s), ())) - - /** set the value viewed through the lens and returns its *new* value */ - def assign(b: B): IndexedState[S, T, B] = - mod(_ => b) - - /** set the value viewed through the lens and returns its *old* value */ - def assigno(b: B): IndexedState[S, T, A] = - modo(_ => b) - - /** set the value viewed through the lens and ignores both values */ - def assign_(b: B): IndexedState[S, T, Unit] = - mod_(_ => b) } diff --git a/state/shared/src/main/scala/monocle/state/StateOptionalSyntax.scala b/state/shared/src/main/scala/monocle/state/StateOptionalSyntax.scala index 85e2012b6..bec9bd031 100644 --- a/state/shared/src/main/scala/monocle/state/StateOptionalSyntax.scala +++ b/state/shared/src/main/scala/monocle/state/StateOptionalSyntax.scala @@ -2,7 +2,7 @@ package monocle.state import monocle.POptional -import scalaz.{IndexedState, State} +import cats.data.State trait StateOptionalSyntax { implicit def toStateOptionalOps[S, T, A, B](optional: POptional[S, T, A, B]): StateOptionalOps[S, T, A, B] = @@ -25,28 +25,4 @@ final class StateOptionalOps[S, T, A, B](optional: POptional[S, T, A, B]) { /** extracts the value viewed through the optional and applies `f` over it */ def extracts[B](f: A => B): State[S, Option[B]] = extract.map(_.map(f)) - - /** modify the value viewed through the Optional and return its *new* value, if there is one */ - def mod(f: A => B): IndexedState[S, T, Option[B]] = - modo(f).map(_.map(f)) - - /** modify the value viewed through the Optional and return its *old* value, if there was one */ - def modo(f: A => B): IndexedState[S, T, Option[A]] = - IndexedState(s => (optional.modify(f)(s), optional.getOption(s))) - - /** modify the value viewed through the Optional and ignores both values */ - def mod_(f: A => B): IndexedState[S, T, Unit] = - IndexedState(s => (optional.modify(f)(s), ())) - - /** set the value viewed through the Optional and returns its *new* value */ - def assign(b: B): IndexedState[S, T, Option[B]] = - mod(_ => b) - - /** set the value viewed through the Optional and return its *old* value, if there was one */ - def assigno(b: B): IndexedState[S, T, Option[A]] = - modo(_ => b) - - /** set the value viewed through the Optional and ignores both values */ - def assign_(b: B): IndexedState[S, T, Unit] = - mod_(_ => b) } diff --git a/state/shared/src/main/scala/monocle/state/StateSetterSyntax.scala b/state/shared/src/main/scala/monocle/state/StateSetterSyntax.scala deleted file mode 100644 index 53078b566..000000000 --- a/state/shared/src/main/scala/monocle/state/StateSetterSyntax.scala +++ /dev/null @@ -1,20 +0,0 @@ -package monocle.state - -import monocle.PSetter - -import scalaz.IndexedState - -trait StateSetterSyntax { - implicit def toStateSetterOps[S, T, A, B](setter: PSetter[S, T, A, B]): StateSetterOps[S, T, A, B] = - new StateSetterOps[S, T, A, B](setter) -} - -final class StateSetterOps[S, T, A, B](setter: PSetter[S, T, A, B]) { - /** modify the value referenced through the setter */ - def mod_(f: A => B): IndexedState[S, T, Unit] = - IndexedState(s => (setter.modify(f)(s), ())) - - /** set the value referenced through the setter */ - def assign_(b: B): IndexedState[S, T, Unit] = - mod_(_ => b) -} diff --git a/test/jvm/src/test/scala/monocle/PlatformSpecificTestInstances.scala b/test/jvm/src/test/scala/monocle/PlatformSpecificTestInstances.scala index 744a010f7..2c7b54b01 100644 --- a/test/jvm/src/test/scala/monocle/PlatformSpecificTestInstances.scala +++ b/test/jvm/src/test/scala/monocle/PlatformSpecificTestInstances.scala @@ -2,10 +2,10 @@ package monocle import java.net.URL import org.scalacheck.{Arbitrary, Cogen, Gen} -import scalaz.Equal +import cats.{Eq => Equal} private [monocle] trait PlatformSpecificTestInstances { - implicit val urlEqual = Equal.equalA[URL] + implicit val urlEqual = Equal.fromUniversalEquals[URL] implicit def urlArbitrary: Arbitrary[URL] = Arbitrary { val idGen = Gen.nonEmptyListOf(Gen.alphaChar).map(_.mkString) diff --git a/test/shared/src/test/scala/monocle/FoldSpec.scala b/test/shared/src/test/scala/monocle/FoldSpec.scala index a85832c88..9673154fd 100644 --- a/test/shared/src/test/scala/monocle/FoldSpec.scala +++ b/test/shared/src/test/scala/monocle/FoldSpec.scala @@ -1,9 +1,8 @@ package monocle -import scalaz.std.anyVal._ -import scalaz.std.list._ -import scalaz.std.string._ -import scalaz.{-\/, Category, Choice, Compose, Monoid, Unzip} +import cats.Monoid +import cats.arrow.{Category, Choice, Compose} +import scala.{Left => -\/} class FoldSpec extends MonocleSuite { @@ -12,7 +11,7 @@ class FoldSpec extends MonocleSuite { def nestedListFold[A] = new Fold[List[List[A]], List[A]]{ def foldMap[M: Monoid](f: (List[A]) => M)(s: List[List[A]]): M = - s.foldRight(Monoid[M].zero)((l, acc) => Monoid[M].append(f(l), acc)) + s.foldRight(Monoid[M].empty)((l, acc) => Monoid[M].combine(f(l), acc)) } // test implicit resolution of type classes @@ -29,12 +28,6 @@ class FoldSpec extends MonocleSuite { Choice[Fold].choice(eachLi, Choice[Fold].id[Int]).fold(-\/(List(1,2,3))) shouldEqual 6 } - test("Fold has an Unzip instance") { - val (int, string) = Unzip[Fold[List[(Int, String)], ?]].unzip(eachL2[Int, String]) - int.fold(List((1, "a"), (2, "b"))) shouldEqual 3 - string.fold(List((1, "a"), (2, "b"))) shouldEqual "ab" - } - test("foldMap") { eachLi.foldMap(_.toString)(List(1,2,3,4,5)) shouldEqual "12345" diff --git a/test/shared/src/test/scala/monocle/GetterSpec.scala b/test/shared/src/test/scala/monocle/GetterSpec.scala index fd5d8c0bd..55c3e990c 100644 --- a/test/shared/src/test/scala/monocle/GetterSpec.scala +++ b/test/shared/src/test/scala/monocle/GetterSpec.scala @@ -1,6 +1,9 @@ package monocle -import scalaz._ +import cats.{Cartesian => Zip} +import cats.arrow.{Arrow, Category, Compose, Choice} +import cats.functor.Profunctor +import scala.{Left => -\/} class GetterSpec extends MonocleSuite { @@ -25,29 +28,18 @@ class GetterSpec extends MonocleSuite { Choice[Getter].choice(i, Choice[Getter].id[Int]).get(-\/(Bar(3))) shouldEqual 3 } - test("Getter has a Split instance") { - Split[Getter].split(i, bar).get((Bar(3), Foo(Bar(3)))) shouldEqual ((3, Bar(3))) - } - test("Getter has a Profunctor instance") { - Profunctor[Getter].mapsnd(bar)(_.i).get(Foo(Bar(3))) shouldEqual 3 + Profunctor[Getter].rmap(bar)(_.i).get(Foo(Bar(3))) shouldEqual 3 } test("Getter has a Arrow instance") { - Arrow[Getter].arr((_: Int) * 2).get(4) shouldEqual 8 + Arrow[Getter].lift((_: Int) * 2).get(4) shouldEqual 8 } test("Getter has a Zip instance") { val length = Getter[String, Int](_.length) val upper = Getter[String, String](_.toUpperCase) - Zip[Getter[String, ?]].zip(length, upper).get("helloworld") shouldEqual((10, "HELLOWORLD")) - } - - test("Getter has an Unzip instance") { - val lengthAndUpper = Getter[String, (Int, String)](s => s.length -> s.toUpperCase) - val (length, upper) = Unzip[Getter[String, ?]].unzip(lengthAndUpper) - length.get("helloworld") shouldEqual 10 - upper.get("helloworld") shouldEqual "HELLOWORLD" + Zip[Getter[String, ?]].product(length, upper).get("helloworld") shouldEqual((10, "HELLOWORLD")) } test("get") { @@ -69,13 +61,4 @@ class GetterSpec extends MonocleSuite { val upper = Getter[String, String](_.toUpperCase) length.zip(upper).get("helloworld") shouldEqual((10, "HELLOWORLD")) } - - test("zip/unzip roundtrip") { - val length = Getter[String, Int](_.length) - val upper = Getter[String, String](_.toUpperCase) - - val (length1, upper1) = Unzip[Getter[String, ?]].unzip(length.zip(upper)) - length1.get("helloworld") shouldEqual length.get("helloworld") - upper.get("helloworld") shouldEqual upper.get("helloworld") - } } diff --git a/test/shared/src/test/scala/monocle/IsoSpec.scala b/test/shared/src/test/scala/monocle/IsoSpec.scala index 8162e86a3..e3e558eeb 100644 --- a/test/shared/src/test/scala/monocle/IsoSpec.scala +++ b/test/shared/src/test/scala/monocle/IsoSpec.scala @@ -5,8 +5,8 @@ import monocle.macros.GenIso import org.scalacheck.{Arbitrary, Gen} import org.scalacheck.Arbitrary._ -import scalaz.std.anyVal._ -import scalaz.{Category, Compose, Equal, Split} +import cats.{Eq => Equal} +import cats.arrow.{Category, Compose} class IsoSpec extends MonocleSuite { @@ -23,23 +23,23 @@ class IsoSpec extends MonocleSuite { case class IntWrapper(i: Int) implicit val intWrapperGen: Arbitrary[IntWrapper] = Arbitrary(arbitrary[Int].map(IntWrapper.apply)) - implicit val intWrapperEq = Equal.equalA[IntWrapper] + implicit val intWrapperEq = Equal.fromUniversalEquals[IntWrapper] case class IdWrapper[A](value: A) implicit def idWrapperGen[A: Arbitrary]: Arbitrary[IdWrapper[A]] = Arbitrary(arbitrary[A].map(IdWrapper.apply)) - implicit def idWrapperEq[A: Equal]: Equal[IdWrapper[A]] = Equal.equalA + implicit def idWrapperEq[A: Equal]: Equal[IdWrapper[A]] = Equal.fromUniversalEquals case object AnObject implicit val anObjectGen: Arbitrary[AnObject.type] = Arbitrary(Gen.const(AnObject)) - implicit val anObjectEq = Equal.equalA[AnObject.type] + implicit val anObjectEq = Equal.fromUniversalEquals[AnObject.type] case class EmptyCase() implicit val emptyCaseGen: Arbitrary[EmptyCase] = Arbitrary(Gen.const(EmptyCase())) - implicit val emptyCaseEq = Equal.equalA[EmptyCase] + implicit val emptyCaseEq = Equal.fromUniversalEquals[EmptyCase] case class EmptyCaseType[A]() implicit def emptyCaseTypeGen[A]: Arbitrary[EmptyCaseType[A]] = Arbitrary(Gen.const(EmptyCaseType())) - implicit def emptyCaseTypeEq[A] = Equal.equalA[EmptyCaseType[A]] + implicit def emptyCaseTypeEq[A] = Equal.fromUniversalEquals[EmptyCaseType[A]] val iso = Iso[IntWrapper, Int](_.i)(IntWrapper.apply) @@ -73,15 +73,11 @@ class IsoSpec extends MonocleSuite { Category[Iso].id[Int].get(3) shouldEqual 3 } - test("Iso has a Split instance") { - Split[Iso].split(iso, iso.reverse).get((IntWrapper(3), 3)) shouldEqual ((3, IntWrapper(3))) - } - test("mapping") { - import scalaz.Id._ + import cats.Id - iso.mapping[Id].get(id.pure(IntWrapper(3))) shouldEqual id.pure(3) - iso.mapping[Id].reverseGet(id.pure(3)) shouldEqual id.pure(IntWrapper(3)) + iso.mapping[Id].get(IntWrapper(3)) shouldEqual 3 + iso.mapping[Id].reverseGet(3) shouldEqual IntWrapper(3) } test("apply") { diff --git a/test/shared/src/test/scala/monocle/LensSpec.scala b/test/shared/src/test/scala/monocle/LensSpec.scala index c6105df31..5452549b8 100644 --- a/test/shared/src/test/scala/monocle/LensSpec.scala +++ b/test/shared/src/test/scala/monocle/LensSpec.scala @@ -5,7 +5,9 @@ import monocle.macros.{GenLens, Lenses} import org.scalacheck.Arbitrary import org.scalacheck.Arbitrary._ -import scalaz._ +import cats.{Eq => Equal} +import cats.arrow.{Category, Choice, Compose} +import scala.{Right => \/-} case class Point(x: Int, y: Int) @Lenses case class Example(s: String, p: Point) @@ -30,9 +32,6 @@ class LensSpec extends MonocleSuite { val s = Lens[Example, String](_.s)(s => ex => ex.copy(s = s)) val p = Lens[Example, Point](_.p)(p => ex => ex.copy(p = p)) - val t = PLens.fromStore[Example, Example, String, String] { ex => - Store(s => ex.copy(s = s), ex.s) - } val x = Lens[Point, Int](_.x)(x => p => p.copy(x = x)) val y = Lens[Point, Int](_.y)(y => p => p.copy(y = y)) @@ -44,10 +43,9 @@ class LensSpec extends MonocleSuite { y <- arbitrary[Int] } yield Example(s, Point(x, y))) - implicit val exampleEq = Equal.equalA[Example] + implicit val exampleEq = Equal.fromUniversalEquals[Example] checkAll("apply Lens", LensTests(s)) - checkAll("Store-coalgebra Lens", LensTests(t)) checkAll("GenLens", LensTests(GenLens[Example](_.s))) checkAll("GenLens chain", LensTests(GenLens[Example](_.p.x))) checkAll("Lenses", LensTests(Example.s)) @@ -73,16 +71,6 @@ class LensSpec extends MonocleSuite { Choice[Lens].choice(x, y).get(\/-(Point(5, 6))) shouldEqual 6 } - test("Lens has a Split instance") { - Split[Lens].split(x, y).get((Point(0, 1), Point(5, 6))) shouldEqual ((0, 6)) - } - - test("Lens has an Unzip instance") { - val (unzipX, unzipY) = Unzip[Lens[Point, ?]].unzip(xy) - unzipX.get(Point(1, 2)) shouldEqual 1 - unzipY.get(Point(1, 2)) shouldEqual 2 - } - test("get") { x.get(Point(5, 2)) shouldEqual 5 } diff --git a/test/shared/src/test/scala/monocle/MonocleSuite.scala b/test/shared/src/test/scala/monocle/MonocleSuite.scala index 6c43cf1e7..3e07c6a77 100644 --- a/test/shared/src/test/scala/monocle/MonocleSuite.scala +++ b/test/shared/src/test/scala/monocle/MonocleSuite.scala @@ -21,5 +21,4 @@ trait MonocleSuite extends FunSuite with StateLensSyntax with StateOptionalSyntax with StateGetterSyntax - with StateSetterSyntax with ReaderGetterSyntax diff --git a/test/shared/src/test/scala/monocle/OptionalSpec.scala b/test/shared/src/test/scala/monocle/OptionalSpec.scala index 97c4bc450..6325a22ce 100644 --- a/test/shared/src/test/scala/monocle/OptionalSpec.scala +++ b/test/shared/src/test/scala/monocle/OptionalSpec.scala @@ -2,7 +2,8 @@ package monocle import monocle.law.discipline.{OptionalTests, SetterTests, TraversalTests} -import scalaz._ +import cats.arrow.{Category, Choice, Compose} +import scala.{Left => -\/} class OptionalSpec extends MonocleSuite { @@ -43,12 +44,6 @@ class OptionalSpec extends MonocleSuite { Choice[Optional].choice(headOptionI, Category[Optional].id[Int]).getOption(-\/(List(1,2,3))) shouldEqual Some(1) } - test("Optional has an Unzip instance") { - val (int, string) = Unzip[Optional[List[(Int, String)], ?]].unzip(headOption2[Int, String]) - int.getOption(List((1, "a"))) shouldEqual Some(1) - string.getOption(List((1, "a"))) shouldEqual Some("a") - } - test("getOption") { headOptionI.getOption(List(1,2,3,4)) shouldEqual Some(1) diff --git a/test/shared/src/test/scala/monocle/PrismSpec.scala b/test/shared/src/test/scala/monocle/PrismSpec.scala index 9ec40d318..6e89c76c9 100644 --- a/test/shared/src/test/scala/monocle/PrismSpec.scala +++ b/test/shared/src/test/scala/monocle/PrismSpec.scala @@ -4,8 +4,9 @@ import monocle.law.discipline.{OptionalTests, PrismTests, SetterTests, Traversal import monocle.macros.GenIso import monocle.macros.GenPrism -import scalaz._ -import scalaz.std.list._ +import cats.arrow.{Category, Compose} +import cats.syntax.either._ +import scala.{Either => \/, Right => \/-} class PrismSpec extends MonocleSuite { diff --git a/test/shared/src/test/scala/monocle/SetterSpec.scala b/test/shared/src/test/scala/monocle/SetterSpec.scala index 86d972a5e..1a32063e2 100644 --- a/test/shared/src/test/scala/monocle/SetterSpec.scala +++ b/test/shared/src/test/scala/monocle/SetterSpec.scala @@ -1,7 +1,7 @@ package monocle -import scalaz.std.list._ -import scalaz.{Category, Choice, Compose, Unzip, \/-} +import cats.arrow.{Category, Choice, Compose} +import scala.{Right => \/-} class SetterSpec extends MonocleSuite { @@ -25,12 +25,6 @@ class SetterSpec extends MonocleSuite { Choice[Setter].choice(eachL[Int], even[Int]).modify(_ + 1)(\/-(List(1,2,3,4))) shouldEqual \/-(List(2,2,4,4)) } - test("Setter has an Unzip instance") { - val (int, string) = Unzip[Setter[List[(Int, String)], ?]].unzip(eachL2[Int, String]) - int.modify(_ + 1)(List((1, "a"), (2, "b"))) shouldEqual List((2, "a"), (3, "b")) - string.modify(_ + "!")(List((1, "a"), (2, "b"))) shouldEqual List((1, "a!"), (2, "b!")) - } - test("set") { eachLi.set(0)(List(1,2,3,4)) shouldEqual List(0,0,0,0) diff --git a/test/shared/src/test/scala/monocle/TestInstances.scala b/test/shared/src/test/scala/monocle/TestInstances.scala index c6a3a4575..9610c4545 100644 --- a/test/shared/src/test/scala/monocle/TestInstances.scala +++ b/test/shared/src/test/scala/monocle/TestInstances.scala @@ -8,121 +8,58 @@ import org.scalacheck.rng.Seed import org.scalacheck.{Arbitrary, Cogen, Gen} import org.scalactic.Equality -import scalaz.Tree.Node -import scalaz.\&/.{Both, That, This} -import scalaz._ -import scalaz.std.list._ -import scalaz.syntax.traverse._ -import scalaz.syntax.equal._ +import cats.data.{Ior => \&/, NonEmptyList, OneAnd, Validated => Validation} +import cats.data.Ior.{Both, Right => That, Left => This} +import cats.{Eq => Equal, _} +import cats.free.Cofree +import cats.syntax.either._ +import cats.syntax.eq._ +import scala.{Either => \/, List => IList} -trait TestInstances extends PlatformSpecificTestInstances { +trait TestInstances extends PlatformSpecificTestInstances with cats.instances.AllInstances { implicit def equality[A](implicit A: Equal[A]): Equality[A] = new Equality[A]{ override def areEqual(a: A, b: Any): Boolean = - A.equal(a, b.asInstanceOf[A]) + A.eqv(a, b.asInstanceOf[A]) } implicit val genApplicative: Applicative[Gen] = new Applicative[Gen] { - override def ap[A, B](fa: => Gen[A])(f: => Gen[A => B]): Gen[B] = fa.flatMap(a => f.map(_(a))) - override def point[A](a: => A): Gen[A] = Gen.const(a) + override def ap[A, B](f: Gen[A => B])(fa: Gen[A]): Gen[B] = fa.flatMap(a => f.map(_(a))) + override def pure[A](a: A): Gen[A] = Gen.const(a) } // Equal instances - implicit val booleanEqual = Equal.equalA[Boolean] - implicit val byteEqual = Equal.equalA[Byte] - implicit val shortEqual = Equal.equalA[Short] - implicit val charEqual = Equal.equalA[Char] - implicit val intEqual = Equal.equalA[Int] - implicit val longEqual = Equal.equalA[Long] - implicit val floatEqual = Equal.equalA[Float] - implicit val doubleEqual = Equal.equalA[Double] - implicit val stringEqual = Equal.equalA[String] - implicit val unitEqual = Equal.equalA[Unit] - implicit val bigIntEqual = Equal.equalA[BigInt] - implicit val bigDecimalEqual = Equal.equalA[BigDecimal] - implicit val uuidEqual = Equal.equalA[UUID] - implicit val uriEqual = Equal.equalA[URI] - - implicit val aritiesEq = Equal.equalA[Arities] - implicit val nullaryEq = Equal.equalA[Nullary] - implicit val unaryEq = Equal.equalA[Unary] - implicit val binaryEq = Equal.equalA[Binary] - implicit val quintaryEq = Equal.equalA[Quintary] - - implicit def optEq[A: Equal] = scalaz.std.option.optionEqual[A] - implicit def someEq[A: Equal] = Equal.equalA[Some[A]] - implicit def eitherEq[A: Equal, B: Equal] = scalaz.std.either.eitherEqual[A, B] - implicit def listEq[A: Equal] = scalaz.std.list.listEqual[A] - implicit def vectorEq[A: Equal] = scalaz.std.vector.vectorEqual[A] - implicit def streamEq[A: Equal] = scalaz.std.stream.streamEqual[A] - implicit def setEq[A: Order] = scalaz.std.set.setOrder[A] - implicit def mapEq[K: Order, V: Equal] = scalaz.std.map.mapEqual[K, V] - - implicit def tuple2Eq[A1: Equal, A2: Equal] = scalaz.std.tuple.tuple2Equal[A1, A2] - implicit def tuple3Eq[A1: Equal, A2: Equal, A3: Equal] = scalaz.std.tuple.tuple3Equal[A1, A2, A3] - implicit def tuple4Eq[A1: Equal, A2: Equal, A3: Equal, A4: Equal] = scalaz.std.tuple.tuple4Equal[A1, A2, A3, A4] - implicit def tuple5Eq[A1: Equal, A2: Equal, A3: Equal, A4: Equal, A5: Equal] = scalaz.std.tuple.tuple5Equal[A1, A2, A3, A4, A5] - implicit def tuple6Eq[A1: Equal, A2: Equal, A3: Equal, A4: Equal, A5: Equal, A6: Equal] = scalaz.std.tuple.tuple6Equal[A1, A2, A3, A4, A5, A6] + implicit val uriEqual = Equal.fromUniversalEquals[URI] + + implicit val aritiesEq = Equal.fromUniversalEquals[Arities] + implicit val nullaryEq = Equal.fromUniversalEquals[Nullary] + implicit val unaryEq = Equal.fromUniversalEquals[Unary] + implicit val binaryEq = Equal.fromUniversalEquals[Binary] + implicit val quintaryEq = Equal.fromUniversalEquals[Quintary] implicit def optionCofreeEq[A](implicit A: Equal[A]): Equal[Cofree[Option, A]] = - Equal.equal { (a, b) => A.equal(a.head, b.head) && a.tail === b.tail } + Equal.instance { (a, b) => A.eqv(a.head, b.head) && a.tail === b.tail } implicit def streamCofreeEq[A](implicit A: Equal[A]): Equal[Cofree[Stream, A]] = - Equal.equal { (a, b) => A.equal(a.head, b.head) && a.tail === b.tail } + Equal.instance { (a, b) => A.eqv(a.head, b.head) && a.tail === b.tail } implicit def function1Eq[A, B](implicit A: Arbitrary[A], B: Equal[B]) = new Equal[A => B] { val samples = Stream.continually(A.arbitrary.sample).flatten val samplesCount = 50 - override def equal(f: A => B, g: A => B) = - samples.take(samplesCount).forall { a => B.equal(f(a), g(a)) } + override def eqv(f: A => B, g: A => B) = + samples.take(samplesCount).forall { a => B.eqv(f(a), g(a)) } } implicit def pisoEq[S, T, A, B](implicit StoA: Equal[S => A], BtoT: Equal[B => T]): Equal[PIso[S, T, A, B]] = - Equal.equal { (a, b) => StoA.equal(a.get, b.get) && BtoT.equal(a.reverseGet, b.reverseGet) } + Equal.instance { (a, b) => StoA.eqv(a.get, b.get) && BtoT.eqv(a.reverseGet, b.reverseGet) } implicit def pprismEq[S, T, A, B](implicit StoOptA: Equal[S => Option[A]], BtoT: Equal[B => T]): Equal[PPrism[S, T, A, B]] = - Equal.equal { (a, b) => StoOptA.equal(a.getOption, b.getOption) && BtoT.equal(a.reverseGet, b.reverseGet) } - - // Order instances - - implicit val intOrder = Order.fromScalaOrdering[Int] - - // Show instances - - implicit val intShow = Show.showA[Int] - - implicit def treeShow[A: Show] = new Show[Tree[A]] { - override def shows(f: Tree[A]): String = f.drawTree - } - - implicit def streamShow[A: Show] = scalaz.std.stream.streamShow[A] + Equal.instance { (a, b) => StoOptA.eqv(a.getOption, b.getOption) && BtoT.eqv(a.reverseGet, b.reverseGet) } // Arbitrary instances - implicit def treeArbitrary[A: Arbitrary]: Arbitrary[Tree[A]] = - Arbitrary { - def genPartition(sum: Int): Gen[List[Int]] = - if(sum <= 0) Gen.const(Nil) - else for { - n <- Gen.choose(1, sum) - tail <- genPartition(sum - n) - } yield n :: tail - - def sizedTree(size: Int): Gen[Tree[A]] = - for { - value <- Arbitrary.arbitrary[A] - partitions <- genPartition(size - 1) - children <- partitions.traverseU(sizedTree) - } yield Node[A](value, children.toStream) - - Gen.sized(sz => sizedTree(sz)) - } - - implicit def treeCoGen[A: Cogen]: Cogen[Tree[A]] = - Cogen[Tree[A]]((seed: Seed, t: Tree[A]) => Cogen[(A, Stream[Tree[A]])].perturb(seed, (t.rootLabel, t.subForest))) - implicit def streamCoGen[A: Cogen]: Cogen[Stream[A]] = Cogen[List[A]].contramap[Stream[A]](_.toList) implicit def optionArbitrary[A: Arbitrary]: Arbitrary[Option[A]] = Arbitrary(Gen.frequency( @@ -130,23 +67,10 @@ trait TestInstances extends PlatformSpecificTestInstances { 3 -> Arbitrary.arbitrary[A].map(Option(_)) )) - implicit def maybeArbitrary[A: Arbitrary]: Arbitrary[Maybe[A]] = Arbitrary(Gen.frequency( - 1 -> Maybe.empty[A], - 3 -> Arbitrary.arbitrary[A].map(Maybe.just(_)) - )) - - implicit def iListCoGen[A: Cogen]: Cogen[IList[A]] = Cogen[List[A]].contramap[IList[A]](_.toList) - implicit def someArbitrary[A: Arbitrary]: Arbitrary[Some[A]] = Arbitrary(Arbitrary.arbitrary[A].map(Some(_))) - implicit def disjunctionArbitrary[A: Arbitrary, B: Arbitrary]: Arbitrary[A \/ B] = - Arbitrary(arbitrary[Either[A, B]] map \/.fromEither) - - implicit def coGenDisjunction[E: Cogen, A: Cogen]: Cogen[E \/ A] = - Cogen.cogenEither[E, A].contramap[E \/ A](_.toEither) - implicit def validationArbitrary[A: Arbitrary, B: Arbitrary]: Arbitrary[Validation[A, B]] = - Arbitrary(arbitrary[A \/ B].map(_.validation)) + Arbitrary(arbitrary[A \/ B].map(_.toValidated)) implicit def coGenValidation[E: Cogen, A: Cogen]: Cogen[Validation[E, A]] = Cogen.cogenEither[E, A].contramap[Validation[E, A]](_.toEither) @@ -171,47 +95,28 @@ trait TestInstances extends PlatformSpecificTestInstances { implicit def vectorArbitrary[A: Arbitrary]: Arbitrary[Vector[A]] = Arbitrary(Arbitrary.arbitrary[List[A]].map(_.toVector)) - implicit def iListArbitrary[A: Arbitrary]: Arbitrary[IList[A]] = - Arbitrary(Arbitrary.arbitrary[List[A]].map(IList.fromList)) - implicit def mapArbitrary[K: Arbitrary, V: Arbitrary] = Arbitrary(Arbitrary.arbitrary[List[(K,V)]].map(_.toMap)) - implicit def iMapArbitrary[K: Arbitrary: Order, V: Arbitrary] = - Arbitrary(Arbitrary.arbitrary[List[(K,V)]].map(l => ==>>.fromList(l)(Order[K]))) - implicit def setArbitrary[A: Arbitrary]: Arbitrary[Set[A]] = Arbitrary(Arbitrary.arbitrary[List[A]].map(_.toSet)) - implicit def iSetArbitrary[A: Arbitrary: Order]: Arbitrary[ISet[A]] = - Arbitrary(Arbitrary.arbitrary[List[A]].map(l => ISet.fromList(l)(Order[A]))) - implicit def nelArbitrary[A: Arbitrary]: Arbitrary[NonEmptyList[A]] = - Arbitrary(oneAndArbitrary[List,A].arbitrary.map( o => NonEmptyList(o.head, o.tail:_*))) + Arbitrary(oneAndArbitrary[List,A].arbitrary.map( o => NonEmptyList(o.head, o.tail))) implicit def nelCoGen[A: Cogen]: Cogen[NonEmptyList[A]] = Cogen[(A, IList[A])].contramap[NonEmptyList[A]](nel => (nel.head, nel.tail)) - implicit def either3Arbitrary[A: Arbitrary, B: Arbitrary, C: Arbitrary]: Arbitrary[Either3[A, B, C]] = - Arbitrary(Gen.oneOf( - Arbitrary.arbitrary[A].map(Either3.left3), - Arbitrary.arbitrary[B].map(Either3.middle3), - Arbitrary.arbitrary[C].map(Either3.right3) - )) - implicit def optionCofreeArbitrary[A](implicit A: Arbitrary[A]): Arbitrary[Cofree[Option, A]] = Arbitrary(Arbitrary.arbitrary[OneAnd[List, A]].map( xs => monocle.std.cofree.cofreeToStream.reverseGet(xs.copy(tail = xs.tail.toStream)) )) - implicit def streamCofreeArbitrary[A](implicit A: Arbitrary[A]): Arbitrary[Cofree[Stream, A]] = - Arbitrary(Arbitrary.arbitrary[Tree[A]].map( monocle.std.cofree.cofreeToTree.reverseGet)) - implicit def cogenOptionCofree[A](implicit A: Cogen[A]): Cogen[Cofree[Option, A]] = - Cogen[Cofree[Option, A]]((seed: Seed, t: Cofree[Option, A]) => Cogen[(A, Option[Cofree[Option, A]])].perturb(seed, (t.head, t.tail))) + Cogen[Cofree[Option, A]]((seed: Seed, t: Cofree[Option, A]) => Cogen[(A, Option[Cofree[Option, A]])].perturb(seed, (t.head, t.tail.value))) implicit def cogenStreamCofree[A](implicit A: Cogen[A]): Cogen[Cofree[Stream, A]] = - Cogen[Cofree[Stream, A]]((seed: Seed, t: Cofree[Stream, A]) => Cogen[(A, Stream[Cofree[Stream, A]])].perturb(seed, (t.head, t.tail))) + Cogen[Cofree[Stream, A]]((seed: Seed, t: Cofree[Stream, A]) => Cogen[(A, Stream[Cofree[Stream, A]])].perturb(seed, (t.head, t.tail.value))) implicit def uuidArbitrary: Arbitrary[UUID] = Arbitrary(UUID.randomUUID) diff --git a/test/shared/src/test/scala/monocle/TraversalSpec.scala b/test/shared/src/test/scala/monocle/TraversalSpec.scala index c836e553e..6656be6d4 100644 --- a/test/shared/src/test/scala/monocle/TraversalSpec.scala +++ b/test/shared/src/test/scala/monocle/TraversalSpec.scala @@ -5,9 +5,9 @@ import monocle.macros.GenLens import org.scalacheck.Arbitrary import org.scalacheck.Arbitrary.arbitrary -import scalaz.{-\/, Category, Choice, Compose, Equal, Unzip} -import scalaz.std.string._ -import scalaz.std.list._ +import cats.{Eq => Equal} +import cats.arrow.{Category, Choice, Compose} +import scala.{Left => -\/} class TraversalSpec extends MonocleSuite { @@ -28,7 +28,7 @@ class TraversalSpec extends MonocleSuite { n <- arbitrary[String] } yield Location(x, y, n)) - implicit val exampleEq = Equal.equalA[Location] + implicit val exampleEq = Equal.fromUniversalEquals[Location] // Below we test a 7-lenses Traversal created using applyN @@ -47,13 +47,6 @@ class TraversalSpec extends MonocleSuite { // the 7-lenses Traversal generated using applyN val traversalN: Traversal[ManyPropObject, Int] = Traversal.applyN(l1,l2,l3,l4,l5,l6,l7) - // the Traversal generated using PTraversal.apply (no lenses involved) - val ptraversalN: Traversal[ManyPropObject, Int] = PTraversal.fromStore { obj => - (toTraversalBuilder(obj.p1) ~ obj.p2 ~ obj.p4 ~ obj.p5 ~ obj.p6 ~ obj.p7 ~ obj.p8) { - ManyPropObject(_, _, obj.p3, _, _, _, _, _) - } - } - // the stub for generating random test objects implicit val manyPropObjectGen: Arbitrary[ManyPropObject] = Arbitrary(for { p1 <- arbitrary[Int] @@ -66,11 +59,10 @@ class TraversalSpec extends MonocleSuite { p8 <- arbitrary[Int] } yield ManyPropObject(p1,p2,p3,p4,p5,p6,p7,p8)) - implicit val eqForManyPropObject = Equal.equalA[ManyPropObject] + implicit val eqForManyPropObject = Equal.fromUniversalEquals[ManyPropObject] checkAll("apply2 Traversal", TraversalTests(coordinates)) checkAll("applyN Traversal", TraversalTests(traversalN)) - checkAll("applyN PTraversal", TraversalTests(ptraversalN)) checkAll("fromTraverse Traversal", TraversalTests(eachLi)) checkAll("traversal.asSetter", SetterTests(coordinates.asSetter)) @@ -90,12 +82,6 @@ class TraversalSpec extends MonocleSuite { Choice[Traversal].choice(eachL[Int], coordinates).modify(_ + 1)(-\/(List(1,2,3))) shouldEqual -\/(List(2,3,4)) } - test("Traversal has an Unzip instance") { - val (int, string) = Unzip[Traversal[List[(Int, String)], ?]].unzip(eachL2[Int, String]) - int.getAll(List((1, "a"), (2, "b"))) shouldEqual List(1, 2) - string.getAll(List((1, "a"), (2, "b"))) shouldEqual List("a", "b") - } - test("foldMap") { eachLi.foldMap(_.toString)(List(1,2,3,4,5)) shouldEqual "12345" diff --git a/test/shared/src/test/scala/monocle/function/Cons1Spec.scala b/test/shared/src/test/scala/monocle/function/Cons1Spec.scala index 1903d13ce..1fc9074cc 100644 --- a/test/shared/src/test/scala/monocle/function/Cons1Spec.scala +++ b/test/shared/src/test/scala/monocle/function/Cons1Spec.scala @@ -3,7 +3,7 @@ package monocle.function import monocle.MonocleSuite import monocle.law.discipline.function.Cons1Tests -import scalaz.IList +import scala.{List => IList} class Cons1Spec extends MonocleSuite { diff --git a/test/shared/src/test/scala/monocle/function/Data.scala b/test/shared/src/test/scala/monocle/function/Data.scala index e54f01d66..8ff9d6a03 100644 --- a/test/shared/src/test/scala/monocle/function/Data.scala +++ b/test/shared/src/test/scala/monocle/function/Data.scala @@ -3,8 +3,9 @@ package monocle.function import monocle._ import org.scalacheck.{Cogen, Arbitrary} -import scalaz.{NonEmptyList, Equal} -import scalaz.syntax.applicative._ +import cats.{Eq => Equal} +import cats.data.NonEmptyList +import cats.syntax.apply._ case class MMap[K, V](map: Map[K, V]) @@ -12,7 +13,7 @@ object MMap { def toMap[K, V]: Iso[MMap[K, V], Map[K, V]] = Iso[MMap[K, V], Map[K, V]](_.map)(MMap(_)) - implicit def mmapEq[K, V]: Equal[MMap[K, V]] = Equal.equalA + implicit def mmapEq[K, V]: Equal[MMap[K, V]] = Equal.fromUniversalEquals implicit def mmapArb[K: Arbitrary, V: Arbitrary]: Arbitrary[MMap[K, V]] = Arbitrary(Arbitrary.arbitrary[Map[K, V]].map(MMap(_))) } @@ -21,10 +22,10 @@ case class CNel(head: Char, tail: List[Char]) object CNel extends TestInstances { val toNel: Iso[CNel, NonEmptyList[Char]] = - Iso[CNel, NonEmptyList[Char]](c => NonEmptyList(c.head, c.tail: _*))(n => CNel(n.head, n.tail.toList)) + Iso[CNel, NonEmptyList[Char]](c => NonEmptyList(c.head, c.tail))(n => CNel(n.head, n.tail)) - implicit val cNelEq: Equal[CNel] = Equal.equalA - implicit val cNelArb: Arbitrary[CNel] = Arbitrary(^(Arbitrary.arbitrary[Char], Arbitrary.arbitrary[List[Char]])(CNel.apply)) + implicit val cNelEq: Equal[CNel] = Equal.fromUniversalEquals + implicit val cNelArb: Arbitrary[CNel] = Arbitrary((Arbitrary.arbitrary[Char], Arbitrary.arbitrary[List[Char]]).mapN(CNel.apply)) } case class CList(list: List[Char]) @@ -32,7 +33,7 @@ case class CList(list: List[Char]) object CList { val toList: Iso[CList, List[Char]] = Iso[CList, List[Char]](_.list)(CList(_)) - implicit val clistEq: Equal[CList] = Equal.equalA + implicit val clistEq: Equal[CList] = Equal.fromUniversalEquals implicit val clistArb: Arbitrary[CList] = Arbitrary(Arbitrary.arbitrary[List[Char]].map(CList(_))) implicit val clistCoGen: Cogen[CList] = Cogen.cogenList[Char].contramap[CList](_.list) } @@ -43,12 +44,12 @@ object Raw extends TestInstances { val toTuple: Iso[Raw, (Boolean, Char, Int, Long, Float, Double)] = Iso((r: Raw) => (r.b, r.c, r.i, r.l, r.f, r.d))((Raw.apply _)tupled) - implicit val rawEq: Equal[Raw] = Equal.equalA - implicit val rawArb: Arbitrary[Raw] = Arbitrary(^^^^^( + implicit val rawEq: Equal[Raw] = Equal.fromUniversalEquals + implicit val rawArb: Arbitrary[Raw] = Arbitrary(( Arbitrary.arbitrary[Boolean], Arbitrary.arbitrary[Char], Arbitrary.arbitrary[Int], Arbitrary.arbitrary[Long], Arbitrary.arbitrary[Float], - Arbitrary.arbitrary[Double])(Raw.apply)) -} \ No newline at end of file + Arbitrary.arbitrary[Double]).mapN(Raw.apply)) +} diff --git a/test/shared/src/test/scala/monocle/function/Snoc1Spec.scala b/test/shared/src/test/scala/monocle/function/Snoc1Spec.scala index 771ff3f4f..891ba325c 100644 --- a/test/shared/src/test/scala/monocle/function/Snoc1Spec.scala +++ b/test/shared/src/test/scala/monocle/function/Snoc1Spec.scala @@ -3,7 +3,7 @@ package monocle.function import monocle.MonocleSuite import monocle.law.discipline.function.Snoc1Tests -import scalaz.IList +import scala.{List => IList} class Snoc1Spec extends MonocleSuite { diff --git a/test/shared/src/test/scala/monocle/generic/CoproductSpec.scala b/test/shared/src/test/scala/monocle/generic/CoproductSpec.scala index 73985603f..6e51f551c 100644 --- a/test/shared/src/test/scala/monocle/generic/CoproductSpec.scala +++ b/test/shared/src/test/scala/monocle/generic/CoproductSpec.scala @@ -6,7 +6,7 @@ import org.scalacheck.Arbitrary._ import org.scalacheck.{Arbitrary, Gen} import shapeless.{:+:, CNil, Coproduct, Inl, Inr} -import scalaz.Equal +import cats.{Eq => Equal} class CoproductSpec extends MonocleSuite { @@ -18,7 +18,7 @@ class CoproductSpec extends MonocleSuite { )) implicit val isbEqual = new Equal[IB]{ - override def equal(a1: IB, a2: IB): Boolean = (a1, a2) match { + override def eqv(a1: IB, a2: IB): Boolean = (a1, a2) match { case (Inl(i1), Inl(i2)) => i1 == i2 case (Inr(b1), Inr(b2)) => b1 == b2 case _ => false diff --git a/test/shared/src/test/scala/monocle/generic/HListSpec.scala b/test/shared/src/test/scala/monocle/generic/HListSpec.scala index c837a8d5b..54e358495 100644 --- a/test/shared/src/test/scala/monocle/generic/HListSpec.scala +++ b/test/shared/src/test/scala/monocle/generic/HListSpec.scala @@ -7,7 +7,7 @@ import shapeless.HList._ import shapeless.ops.hlist.{Init => HListInit, IsHCons} import shapeless.{::, HNil} -import scalaz.Equal +import cats.{Eq => Equal} class HListSpec extends MonocleSuite { @@ -22,11 +22,11 @@ class HListSpec extends MonocleSuite { type HTail = isHCons.T type HInit = hListinit.Out - implicit val exampleEq = Equal.equalA[Example] - implicit val hEq = Equal.equal[H]((a1, a2) => fromHList[H, Example].get(a1) === fromHList[H, Example].get(a2)) - implicit val reverseHEq = Equal.equal[ReverseH]((a1, a2) => a1.reverse === a2.reverse) - implicit val hTailEq = Equal.equal[HTail]((a1, a2) => (1 :: a1) === (1 :: a2)) - implicit val hInitEq = Equal.equal[HInit]((a1, a2) => (a1.tail :+ 3.5) === (a2.tail :+ 3.5)) + implicit val exampleEq = Equal.fromUniversalEquals[Example] + implicit val hEq = Equal.instance[H]((a1, a2) => fromHList[H, Example].get(a1) === fromHList[H, Example].get(a2)) + implicit val reverseHEq = Equal.instance[ReverseH]((a1, a2) => a1.reverse === a2.reverse) + implicit val hTailEq = Equal.instance[HTail]((a1, a2) => (1 :: a1) === (1 :: a2)) + implicit val hInitEq = Equal.instance[HInit]((a1, a2) => (a1.tail :+ 3.5) === (a2.tail :+ 3.5)) implicit val exampleArb: Arbitrary[Example] = Arbitrary(for{ i <- Arbitrary.arbitrary[Int] diff --git a/test/shared/src/test/scala/monocle/generic/ProductSpec.scala b/test/shared/src/test/scala/monocle/generic/ProductSpec.scala index 8dd409039..25b0034c0 100644 --- a/test/shared/src/test/scala/monocle/generic/ProductSpec.scala +++ b/test/shared/src/test/scala/monocle/generic/ProductSpec.scala @@ -5,13 +5,13 @@ import monocle.law.discipline.IsoTests import monocle.law.discipline.function.EachTests import org.scalacheck.Arbitrary -import scalaz.Equal +import cats.{Eq => Equal} class ProductSpec extends MonocleSuite { case class Person(name: String, age: Int) - implicit val personEq: Equal[Person] = Equal.equalA + implicit val personEq: Equal[Person] = Equal.fromUniversalEquals implicit val personArb: Arbitrary[Person] = Arbitrary(for { n <- Arbitrary.arbitrary[String] a <- Arbitrary.arbitrary[Int] @@ -19,7 +19,7 @@ class ProductSpec extends MonocleSuite { case class Permissions(read: Boolean, write: Boolean, execute: Boolean) - implicit val nameEq: Equal[Permissions] = Equal.equalA + implicit val nameEq: Equal[Permissions] = Equal.fromUniversalEquals implicit val nameArb: Arbitrary[Permissions] = Arbitrary(for { f <- Arbitrary.arbitrary[Boolean] l <- Arbitrary.arbitrary[Boolean] diff --git a/test/shared/src/test/scala/monocle/refined/CharSpec.scala b/test/shared/src/test/scala/monocle/refined/CharSpec.scala index 8e1fb53e7..71df81c5b 100644 --- a/test/shared/src/test/scala/monocle/refined/CharSpec.scala +++ b/test/shared/src/test/scala/monocle/refined/CharSpec.scala @@ -5,7 +5,7 @@ import monocle._ import monocle.law.discipline.PrismTests import org.scalacheck.{Arbitrary, Cogen, Gen} -import scalaz.Equal +import cats.{Eq => Equal} class CharSpec extends MonocleSuite { implicit val lowerCaseRefinedCharArb: Arbitrary[LowerCaseChar] = @@ -17,9 +17,8 @@ class CharSpec extends MonocleSuite { implicit val lowerCaseCoGen: Cogen[LowerCaseChar] = Cogen[Char].contramap[LowerCaseChar](_.value) implicit val upperCaseCoGen: Cogen[UpperCaseChar] = Cogen[Char].contramap[UpperCaseChar](_.value) - implicit val eqLowerCase: Equal[LowerCaseChar] = Equal.equalA[LowerCaseChar] - implicit val eqUpperCase: Equal[UpperCaseChar] = Equal.equalA[UpperCaseChar] - implicit val eqChar: Equal[Char] = Equal.equalA[Char] + implicit val eqLowerCase: Equal[LowerCaseChar] = Equal.fromUniversalEquals[LowerCaseChar] + implicit val eqUpperCase: Equal[UpperCaseChar] = Equal.fromUniversalEquals[UpperCaseChar] checkAll("lower cases", PrismTests(lowerCase)) checkAll("upper cases", PrismTests(upperCase)) diff --git a/test/shared/src/test/scala/monocle/refined/StringsSpec.scala b/test/shared/src/test/scala/monocle/refined/StringsSpec.scala index 5d7c7e606..4d1008f1b 100644 --- a/test/shared/src/test/scala/monocle/refined/StringsSpec.scala +++ b/test/shared/src/test/scala/monocle/refined/StringsSpec.scala @@ -6,7 +6,7 @@ import monocle.MonocleSuite import monocle.law.discipline.PrismTests import org.scalacheck.Cogen -import scalaz.Equal +import cats.{Eq => Equal} class StringsSpec extends MonocleSuite { @@ -14,10 +14,8 @@ class StringsSpec extends MonocleSuite { implicit val startsWithCoGen: Cogen[StartsWithString[W.`"hello"`.T]] = Cogen[String].contramap[StartsWithString[W.`"hello"`.T]](_.value) implicit val endsWithCoGen: Cogen[EndsWithString[W.`"world"`.T]] = Cogen[String].contramap[EndsWithString[W.`"world"`.T]](_.value) - implicit val eqStartsWith: Equal[StartsWithString[W.`"hello"`.T]] = Equal.equalA[StartsWithString[W.`"hello"`.T]] - implicit val eqEndsWith: Equal[EndsWithString[W.`"world"`.T]] = Equal.equalA[EndsWithString[W.`"world"`.T]] - - implicit val eqString: Equal[String] = Equal.equalA[String] + implicit val eqStartsWith: Equal[StartsWithString[W.`"hello"`.T]] = Equal.fromUniversalEquals[StartsWithString[W.`"hello"`.T]] + implicit val eqEndsWith: Equal[EndsWithString[W.`"world"`.T]] = Equal.fromUniversalEquals[EndsWithString[W.`"world"`.T]] checkAll("starts with", PrismTests(startsWith("hello"))) checkAll("ends with", PrismTests(endsWith("world"))) diff --git a/test/shared/src/test/scala/monocle/std/CofreeSpec.scala b/test/shared/src/test/scala/monocle/std/CofreeSpec.scala index 5a300e98c..e993bdc95 100644 --- a/test/shared/src/test/scala/monocle/std/CofreeSpec.scala +++ b/test/shared/src/test/scala/monocle/std/CofreeSpec.scala @@ -4,12 +4,10 @@ import monocle.MonocleSuite import monocle.law.discipline.IsoTests import monocle.law.discipline.function._ -import scalaz.Cofree -import scalaz.std.option.optionInstance +import cats.free.Cofree class CofreeSpec extends MonocleSuite { checkAll("cofreeToStream", IsoTests(cofreeToStream[Int])) - checkAll("cofreeToTree", IsoTests(cofreeToTree[Int])) checkAll("cons1 cofree", Cons1Tests[Cofree[Option, Int], Int, Option[Cofree[Option, Int]]]) checkAll("each cofree", EachTests[Cofree[Option, Int], Int]) } diff --git a/test/shared/src/test/scala/monocle/std/DisjunctionSpec.scala b/test/shared/src/test/scala/monocle/std/DisjunctionSpec.scala deleted file mode 100644 index 8306bf3a7..000000000 --- a/test/shared/src/test/scala/monocle/std/DisjunctionSpec.scala +++ /dev/null @@ -1,17 +0,0 @@ -package monocle.std - -import monocle.MonocleSuite -import monocle.law.discipline.{IsoTests, PrismTests} -import monocle.law.discipline.function.{EachTests, PossibleTests} -import scalaz.\/ - -class DisjunctionSpec extends MonocleSuite { - checkAll("disjunction left" , PrismTests(left[String, Int])) - checkAll("disjunction right", PrismTests(right[String, Int])) - - checkAll("disjunction to Validation", IsoTests(disjunctionToValidation[String, Int])) - checkAll("disjunction to Either" , IsoTests(disjunctionToEither[String, Int])) - - checkAll("each disjunction", EachTests[Unit \/ Int, Int]) - checkAll("possible disjunction", PossibleTests[Unit \/ Int, Int]) -} diff --git a/test/shared/src/test/scala/monocle/std/Either3Spec.scala b/test/shared/src/test/scala/monocle/std/Either3Spec.scala deleted file mode 100644 index 5733905de..000000000 --- a/test/shared/src/test/scala/monocle/std/Either3Spec.scala +++ /dev/null @@ -1,10 +0,0 @@ -package monocle.std - -import monocle.MonocleSuite -import monocle.law.discipline.PrismTests - -class Either3Spec extends MonocleSuite { - checkAll("either3 left3" , PrismTests(left3[String, Int, Char])) - checkAll("either3 middle3", PrismTests(middle3[String, Int, Char])) - checkAll("either3 right3" , PrismTests(right3[String, Int, Char])) -} diff --git a/test/shared/src/test/scala/monocle/std/IListSpec.scala b/test/shared/src/test/scala/monocle/std/IListSpec.scala deleted file mode 100644 index ef10c6522..000000000 --- a/test/shared/src/test/scala/monocle/std/IListSpec.scala +++ /dev/null @@ -1,17 +0,0 @@ -package monocle.std - -import monocle.MonocleSuite -import monocle.function.Plated._ -import monocle.law.discipline.TraversalTests -import monocle.law.discipline.function.{ConsTests, EmptyTests, ReverseTests} - -import scalaz.IList - -class IListSpec extends MonocleSuite { - checkAll("IList Reverse ", ReverseTests[IList[Char]]) - checkAll("IList Empty", EmptyTests[IList[Char]]) - checkAll("IList Cons", ConsTests[IList[Char], Char]) - checkAll("IList Snoc", ConsTests[IList[Char], Char]) - - checkAll("plated IList", TraversalTests(plate[IList[Char]])) -} diff --git a/test/shared/src/test/scala/monocle/std/IMapSpec.scala b/test/shared/src/test/scala/monocle/std/IMapSpec.scala deleted file mode 100644 index f2b30424b..000000000 --- a/test/shared/src/test/scala/monocle/std/IMapSpec.scala +++ /dev/null @@ -1,14 +0,0 @@ -package monocle.std - -import monocle.MonocleSuite -import monocle.law.discipline.function._ - -import scalaz.==>> - -class IMapSpec extends MonocleSuite { - checkAll("at ==>>", AtTests[Int ==>> String, Int, Option[String]]) - checkAll("each ==>>", EachTests[Int ==>> String, String]) - checkAll("empty ==>>", EmptyTests[Int ==>> String]) - checkAll("filterIndex ==>>", FilterIndexTests[Int ==>> Char, Int, Char]) - checkAll("index ==>>", IndexTests[Int ==>> String, Int, String]) -} diff --git a/test/shared/src/test/scala/monocle/std/ISetSpec.scala b/test/shared/src/test/scala/monocle/std/ISetSpec.scala deleted file mode 100644 index 6fd44d79f..000000000 --- a/test/shared/src/test/scala/monocle/std/ISetSpec.scala +++ /dev/null @@ -1,11 +0,0 @@ -package monocle.std - -import monocle.MonocleSuite -import monocle.law.discipline.function.{AtTests, EmptyTests} - -import scalaz.ISet - -class ISetSpec extends MonocleSuite { - checkAll("at ISet", AtTests[ISet[Int], Int, Boolean]) - checkAll("empty ISet", EmptyTests[ISet[Int]]) -} diff --git a/test/shared/src/test/scala/monocle/std/MaybeSpec.scala b/test/shared/src/test/scala/monocle/std/MaybeSpec.scala deleted file mode 100644 index 9b8350add..000000000 --- a/test/shared/src/test/scala/monocle/std/MaybeSpec.scala +++ /dev/null @@ -1,17 +0,0 @@ -package monocle.std - -import monocle.MonocleSuite -import monocle.law.discipline.function.{EachTests, PossibleTests, EmptyTests} -import monocle.law.discipline.{IsoTests, PrismTests} - -import scalaz.Maybe - -class MaybeSpec extends MonocleSuite { - checkAll("maybeToOption", IsoTests(maybeToOption[Int])) - checkAll("just" , PrismTests(just[Int])) - checkAll("nothing", PrismTests(nothing[Long])) - - checkAll("each Maybe", EachTests[Maybe[Int], Int]) - checkAll("empty Maybe", EmptyTests[Maybe[Int]]) - checkAll("possible Maybe", PossibleTests[Maybe[Int], Int]) -} diff --git a/test/shared/src/test/scala/monocle/std/NonEmptyListSpec.scala b/test/shared/src/test/scala/monocle/std/NonEmptyListSpec.scala index fd560e48f..bb04dfb4f 100644 --- a/test/shared/src/test/scala/monocle/std/NonEmptyListSpec.scala +++ b/test/shared/src/test/scala/monocle/std/NonEmptyListSpec.scala @@ -4,7 +4,8 @@ import monocle.MonocleSuite import monocle.law.discipline.IsoTests import monocle.law.discipline.function._ -import scalaz.{IList, NonEmptyList} +import cats.data.NonEmptyList +import scala.{List => IList} class NonEmptyListSpec extends MonocleSuite { checkAll("nelToAndOne", IsoTests(nelToOneAnd[Int])) diff --git a/test/shared/src/test/scala/monocle/std/OneAndSpec.scala b/test/shared/src/test/scala/monocle/std/OneAndSpec.scala index 46beeeed7..a8157cbb9 100644 --- a/test/shared/src/test/scala/monocle/std/OneAndSpec.scala +++ b/test/shared/src/test/scala/monocle/std/OneAndSpec.scala @@ -3,7 +3,7 @@ package monocle.std import monocle.MonocleSuite import monocle.law.discipline.function.{Cons1Tests, EachTests, IndexTests} -import scalaz.OneAnd +import cats.data.OneAnd class OneAndSpec extends MonocleSuite { checkAll("each OneAnd", EachTests[OneAnd[List, Int], Int]) diff --git a/test/shared/src/test/scala/monocle/std/TreeSpec.scala b/test/shared/src/test/scala/monocle/std/TreeSpec.scala deleted file mode 100644 index 88d6c2675..000000000 --- a/test/shared/src/test/scala/monocle/std/TreeSpec.scala +++ /dev/null @@ -1,20 +0,0 @@ -package monocle.std - -import monocle.MonocleSuite -import monocle.function.Plated._ -import monocle.law.discipline.{LensTests, TraversalTests} -import monocle.law.discipline.function.{EachTests, ReverseTests} - -import scalaz.Tree - -class TreeSpec extends MonocleSuite { - checkAll("rootLabel", LensTests(rootLabel[Int])) - checkAll("subForest", LensTests(subForest[Int])) - checkAll("leftMostLabel", LensTests(leftMostLabel[Int])) - checkAll("rightMostLabel", LensTests(rightMostLabel[Int])) - - checkAll("each Tree", EachTests[Tree[Int], Int]) - checkAll("reverse Tree", ReverseTests[Tree[Int], Tree[Int]]) - - checkAll("plated Tree", TraversalTests(plate[Tree[Int]])) -} diff --git a/test/shared/src/test/scala/monocle/std/TrySpec.scala b/test/shared/src/test/scala/monocle/std/TrySpec.scala index 0acd94bc4..7ff59dfb1 100644 --- a/test/shared/src/test/scala/monocle/std/TrySpec.scala +++ b/test/shared/src/test/scala/monocle/std/TrySpec.scala @@ -6,16 +6,16 @@ import monocle.law.discipline.function.{EachTests, PossibleTests} import scala.util.Try -import scalaz.Equal +import cats.{Eq => Equal} class TrySpec extends MonocleSuite { private implicit def tryEqual[A]: Equal[Try[A]] = - Equal.equalA[Try[A]] + Equal.fromUniversalEquals[Try[A]] private implicit def throwableEqual[A]: Equal[Throwable] = - Equal.equalA[Throwable] + Equal.fromUniversalEquals[Throwable] checkAll("trySuccess", PrismTests(monocle.std.utilTry.trySuccess[Int])) checkAll("tryFailure", PrismTests(monocle.std.utilTry.tryFailure[Int])) diff --git a/test/shared/src/test/scala/monocle/std/Tuple1Spec.scala b/test/shared/src/test/scala/monocle/std/Tuple1Spec.scala index 487914960..ad12c6bf3 100644 --- a/test/shared/src/test/scala/monocle/std/Tuple1Spec.scala +++ b/test/shared/src/test/scala/monocle/std/Tuple1Spec.scala @@ -4,17 +4,11 @@ import monocle.MonocleSuite import monocle.law.discipline.{IsoTests, LensTests} import monocle.law.discipline.function.ReverseTests import org.scalacheck.Arbitrary -import scalaz.Equal class Tuple1Spec extends MonocleSuite { implicit def arbitraryTuple1[T](implicit arb: Arbitrary[T]): Arbitrary[Tuple1[T]] = Arbitrary(arb.arbitrary.map(Tuple1.apply)) - implicit def equalTuple1[T](implicit eql: Equal[T]): Equal[Tuple1[T]] = - new Equal[Tuple1[T]]{ - def equal(x: Tuple1[T], y: Tuple1[T]): Boolean = eql.equal(x._1, y._1) - } - checkAll("first tuple1", LensTests(first[Tuple1[Int], Int])) checkAll("reverse tuple1", ReverseTests[Tuple1[Int], Tuple1[Int]]) checkAll("tuple1 iso", IsoTests[Tuple1[Int], Int](tuple1Iso)) diff --git a/test/shared/src/test/scala/monocle/std/ValidationSpec.scala b/test/shared/src/test/scala/monocle/std/ValidationSpec.scala index f8e9ac604..8aafcc8f3 100644 --- a/test/shared/src/test/scala/monocle/std/ValidationSpec.scala +++ b/test/shared/src/test/scala/monocle/std/ValidationSpec.scala @@ -3,7 +3,7 @@ package monocle.std import monocle.MonocleSuite import monocle.law.discipline.{IsoTests, PrismTests} import monocle.law.discipline.function.{EachTests, PossibleTests} -import scalaz.Validation +import cats.data.{Validated => Validation} class ValidationSpec extends MonocleSuite { checkAll("Validation is isomorphic to Disjunction", IsoTests(monocle.std.validation.validationToDisjunction[String, Int])) diff --git a/test/shared/src/test/scala/monocle/unsafe/UnsafeSelectSpec.scala b/test/shared/src/test/scala/monocle/unsafe/UnsafeSelectSpec.scala index 190dcf8eb..633dd0d8c 100644 --- a/test/shared/src/test/scala/monocle/unsafe/UnsafeSelectSpec.scala +++ b/test/shared/src/test/scala/monocle/unsafe/UnsafeSelectSpec.scala @@ -6,7 +6,7 @@ import monocle.macros.GenLens import org.scalacheck.Arbitrary import org.scalatest.prop.GeneratorDrivenPropertyChecks -import scalaz.Equal +import cats.{Eq => Equal} class UnsafeSelectSpec extends MonocleSuite with GeneratorDrivenPropertyChecks { @@ -36,7 +36,7 @@ class UnsafeSelectSpec extends MonocleSuite with GeneratorDrivenPropertyChecks { case class Person(name: String, age: Int) - implicit val personEq: Equal[Person] = Equal.equalA + implicit val personEq: Equal[Person] = Equal.fromUniversalEquals implicit val personGen: Arbitrary[Person] = Arbitrary(for { name <- Arbitrary.arbitrary[String] diff --git a/test/shared/src/test/scala/other/MacroOutSideMonocleSpec.scala b/test/shared/src/test/scala/other/MacroOutSideMonocleSpec.scala index b343d133d..99cd8a4ea 100644 --- a/test/shared/src/test/scala/other/MacroOutSideMonocleSpec.scala +++ b/test/shared/src/test/scala/other/MacroOutSideMonocleSpec.scala @@ -6,8 +6,7 @@ import monocle.macros.{GenIso, GenLens, GenPrism} import org.scalacheck.Arbitrary.{arbOption => _, _} import org.scalacheck.{Cogen, Arbitrary, Gen} -import scalaz.Equal -import scalaz.std.option._ +import cats.{Eq => Equal} class MacroOutSideMonocleSpec extends MonocleSuite { @@ -36,15 +35,15 @@ class MacroOutSideMonocleSpec extends MonocleSuite { implicit def example2TypeArb[A: Arbitrary]: Arbitrary[Example2Type[A]] = Arbitrary(for {x <- arbitrary[A]; y <- Arbitrary.arbOption[A].arbitrary} yield Example2Type(x, y)) - implicit val exampleEq: Equal[Example] = Equal.equalA[Example] - implicit val example2Eq: Equal[Example2] = Equal.equalA[Example2] - implicit def exampleTypeEq[A](implicit as: Equal[Option[A]]): Equal[ExampleType[A]] = as.contramap(_.as) - implicit def example2TypeEq[A](implicit a: Equal[A], as: Equal[Option[A]]): Equal[Example2Type[A]] = Equal.equal((x, y) => a.equal(x.a, y.a) && as.equal(x.as, y.as)) - implicit val exampleObjEq: Equal[ExampleObject.type] = Equal.equalA[ExampleObject.type] - implicit val emptyCaseEq: Equal[EmptyCase] = Equal.equalA[EmptyCase] - implicit def emptyCaseTypeEq[A]: Equal[EmptyCaseType[A]] = Equal.equalA[EmptyCaseType[A]] - implicit val bar1Eq: Equal[Bar1] = Equal.equalA[Bar1] - implicit val fooEq: Equal[Foo] = Equal.equalA[Foo] + implicit val exampleEq: Equal[Example] = Equal.fromUniversalEquals[Example] + implicit val example2Eq: Equal[Example2] = Equal.fromUniversalEquals[Example2] + implicit def exampleTypeEq[A](implicit as: Equal[Option[A]]): Equal[ExampleType[A]] = as.on(_.as) + implicit def example2TypeEq[A](implicit a: Equal[A], as: Equal[Option[A]]): Equal[Example2Type[A]] = Equal.instance((x, y) => a.eqv(x.a, y.a) && as.eqv(x.as, y.as)) + implicit val exampleObjEq: Equal[ExampleObject.type] = Equal.fromUniversalEquals[ExampleObject.type] + implicit val emptyCaseEq: Equal[EmptyCase] = Equal.fromUniversalEquals[EmptyCase] + implicit def emptyCaseTypeEq[A]: Equal[EmptyCaseType[A]] = Equal.fromUniversalEquals[EmptyCaseType[A]] + implicit val bar1Eq: Equal[Bar1] = Equal.fromUniversalEquals[Bar1] + implicit val fooEq: Equal[Foo] = Equal.fromUniversalEquals[Foo] checkAll("GenIso" , IsoTests(GenIso[Example, Int])) checkAll("GenIso.unit object" , IsoTests(GenIso.unit[ExampleObject.type])) From 779372b67e1c19a3ac945e62f56ec73921c69a3d Mon Sep 17 00:00:00 2001 From: Greg Pfeil Date: Sat, 12 Aug 2017 16:53:19 -0400 Subject: [PATCH 2/2] Remove 2.10 and Scala Native support. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Newts doesn’t support 2.10 and neither Cats nor Newts support Scala Native. --- .travis.yml | 26 -------------------------- build.sbt | 38 +++++--------------------------------- 2 files changed, 5 insertions(+), 59 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4f6c7804..0e5f7a49f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: scala scala: - 2.12.2 - 2.11.8 -- 2.10.6 jdk: - oraclejdk8 notifications: @@ -46,28 +45,3 @@ install: - gem install jekyll -v 3.2.1 after_success: - '[[ $TRAVIS_BRANCH == "master" && "${TRAVIS_PULL_REQUEST}" == "false" ]] && { sbt +publish ghpagesPushSite; };' -matrix: - include: - - scala: 2.11.8 - jdk: oraclejdk8 - sudo: required - before_install: - - wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add - - - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - - sudo add-apt-repository -y "deb http://apt.llvm.org/precise/ llvm-toolchain-precise main" - - sudo add-apt-repository -y "deb http://apt.llvm.org/precise/ llvm-toolchain-precise-3.7 main" - - sudo apt-get update -qq - - sudo apt-get install -y libgc-dev clang++-3.7 llvm-3.7 llvm-3.7-dev llvm-3.7-runtime llvm-3.7-tool libunwind7-dev - # Install re2 - # https://github.com/scala-native/scala-native/commit/1d312519788534ff41477e4d7f758a6e7451be05#diff-354f30a63fb0907d4ad57269548329e3R28 - - sudo apt-get install -y make - - export CXX=clang++-3.7 - - git clone https://code.googlesource.com/re2 - - pushd re2 - - git checkout 2017-03-01 - - make -j4 test - - sudo make install prefix=/usr - - make testinstall prefix=/usr - - popd - script: - - sbt ++$TRAVIS_SCALA_VERSION testNative/run diff --git a/build.sbt b/build.sbt index b853c039f..87acac325 100644 --- a/build.sbt +++ b/build.sbt @@ -11,7 +11,7 @@ lazy val Scala211 = "2.11.8" lazy val buildSettings = Seq( organization := "com.github.julien-truffaut", scalaVersion := "2.12.2", - crossScalaVersions := Seq("2.10.6", Scala211, "2.12.2"), + crossScalaVersions := Seq(Scala211, "2.12.2"), scalacOptions ++= Seq( "-deprecation", "-encoding", "UTF-8", @@ -24,8 +24,6 @@ lazy val buildSettings = Seq( "-Ywarn-value-discard", "-Xfuture" ) ++ (CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 10)) => - Seq("-Yno-generic-signatures") // no generic signatures for scala 2.10.x, see SI-7932, #571 and #828 case Some((2, n)) if n >= 11 => Seq("-Ywarn-unused-import") case None => @@ -86,15 +84,9 @@ lazy val scalajsSettings = Seq( "-minSuccessfulTests", "50") ) -lazy val scalanativeSettings = Seq( - scalaVersion := Scala211, - crossScalaVersions := Seq(Scala211) -) - lazy val monocleSettings = buildSettings ++ publishSettings lazy val monocleJvmSettings = monocleSettings lazy val monocleJsSettings = monocleSettings ++ scalajsSettings -lazy val monocleNativeSettings = monocleSettings ++ scalanativeSettings lazy val monocle = project.in(file(".")) .settings(moduleName := "monocle") @@ -116,21 +108,13 @@ lazy val monocleJS = project.in(file(".monocleJS")) .aggregate(coreJS, genericJS, lawJS, macrosJS, stateJS, refinedJS, unsafeJS, testJS) .dependsOn(coreJS, genericJS, lawJS, macrosJS, stateJS, refinedJS, unsafeJS, testJS % "test-internal -> test") -lazy val monocleNative = project.in(file(".monocleNative")) - .settings(monocleNativeSettings) - .settings(noPublishSettings) - .aggregate(coreNative, stateNative, testNative) - .dependsOn(coreNative, stateNative, testNative) - lazy val coreJVM = core.jvm lazy val coreJS = core.js -lazy val coreNative = core.native -lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform) +lazy val core = crossProject(JVMPlatform, JSPlatform) .settings(moduleName := "monocle-core") .configureCross( _.jvmSettings(monocleJvmSettings), - _.jsSettings(monocleJsSettings), - _.nativeSettings(monocleNativeSettings) + _.jsSettings(monocleJsSettings) ) .jvmSettings(mimaSettings("core"): _*) .settings(libraryDependencies ++= Seq(cats.value, catsFree.value, newts.value)) @@ -196,13 +180,11 @@ lazy val macros = crossProject(JVMPlatform, JSPlatform).dependsOn(core) lazy val stateJVM = state.jvm lazy val stateJS = state.js -lazy val stateNative = state.native -lazy val state = crossProject(JVMPlatform, JSPlatform, NativePlatform).dependsOn(core) +lazy val state = crossProject(JVMPlatform, JSPlatform).dependsOn(core) .settings(moduleName := "monocle-state") .configureCross( _.jvmSettings(monocleJvmSettings), - _.jsSettings(monocleJsSettings), - _.nativeSettings(monocleNativeSettings) + _.jsSettings(monocleJsSettings) ) .settings(libraryDependencies ++= Seq(cats.value)) @@ -229,14 +211,6 @@ lazy val test = crossProject(JVMPlatform, JSPlatform).dependsOn(core, generic .settings( libraryDependencies ++= Seq(cats.value, catsLaws.value, shapeless.value, scalatest.value, refinedScalacheck.value, compilerPlugin(paradisePlugin)) ) -lazy val testNative = project.in(file("testNative")).dependsOn(coreNative, stateNative) - .settings(moduleName := "monocle-test-native") - .settings(monocleNativeSettings) - .settings(noPublishSettings) - .settings( - libraryDependencies ++= Seq(cats.value) - ) - .enablePlugins(ScalaNativePlugin) lazy val bench = project.dependsOn(coreJVM, genericJVM, macrosJVM) .settings(moduleName := "monocle-bench") @@ -353,13 +327,11 @@ lazy val publishSettings = Seq( inquireVersions, runTest, releaseStepCommand(s"++$Scala211"), - releaseStepCommand("testNative/run"), setReleaseVersion, commitReleaseVersion, tagRelease, publishArtifacts, releaseStepCommand(s"++$Scala211"), - releaseStepCommand("monocleNative/publishSigned"), setNextVersion, commitNextVersion, pushChanges