From 8b44a0560792ffe900efcbcb398bac7ed302a111 Mon Sep 17 00:00:00 2001 From: sergei-shabanau Date: Fri, 23 Nov 2018 18:17:48 -0500 Subject: [PATCH 1/2] #0 - Restored the reverse `~` combinator --- build.sbt | 3 ++- src/main/scala/scalaz/parsers/Iso.scala | 11 ++++---- .../scala/scalaz/parsers/IsoOpsSpec.scala | 26 +++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/test/scala/scalaz/parsers/IsoOpsSpec.scala diff --git a/build.sbt b/build.sbt index de63ea9..793f8d7 100644 --- a/build.sbt +++ b/build.sbt @@ -14,12 +14,13 @@ lazy val root = (project in file(".")) .settings( name := "scalaz-parsers", + scalacOptions ++= Seq("-Xsource:2.13"), resolvers += "Sonatype OSS Staging".at( "https://oss.sonatype.org/content/repositories/staging" ), libraryDependencies ++= Seq( "org.scalaz" %% "scalaz-zio" % "0.2.9", - "org.scalaz" %% "scalaz-base" % "96627337-SNAPSHOT", + "org.scalaz" %% "scalaz-base" % "e5ebff0a-SNAPSHOT", "org.specs2" %% "specs2-core" % "4.3.5" % Test ) ) diff --git a/src/main/scala/scalaz/parsers/Iso.scala b/src/main/scala/scalaz/parsers/Iso.scala index 32e2374..24a231c 100644 --- a/src/main/scala/scalaz/parsers/Iso.scala +++ b/src/main/scala/scalaz/parsers/Iso.scala @@ -1,5 +1,6 @@ package scalaz.parsers +import scalaz.data.~> import scalaz.tc._ trait Iso[F[_], G[_], A, B] { self => @@ -42,11 +43,11 @@ object Combinators { override def from: UGV[B, A] = (b: B) => AG.or(ab.from(b), abOther.from(b)) } -// def unary_~(implicit GF: G ~> F, FG: F ~> G): Iso[F, G, B, A] = -// new Iso[F, G, B, A] { -// override def to: UFV[B, A] = (b: B) => GF.apply(ab.from(b)) -// override def from: UGV[A, B] = (a: A) => FG.apply(ab.to(a)) -// } + def unary_~(implicit FG: F ~> G, GF: G ~> F): Iso[F, G, B, A] = + new Iso[F, G, B, A] { + override def to: UFV[B, A] = b => GF.apply(ab.from(b)) + override def from: UGV[A, B] = a => FG.apply(ab.to(a)) + } def ⓧ [A2, B2]( other: Iso[F, G, A2, B2] diff --git a/src/test/scala/scalaz/parsers/IsoOpsSpec.scala b/src/test/scala/scalaz/parsers/IsoOpsSpec.scala new file mode 100644 index 0000000..f71ba30 --- /dev/null +++ b/src/test/scala/scalaz/parsers/IsoOpsSpec.scala @@ -0,0 +1,26 @@ +package scalaz.parsers + +import org.specs2.mutable.Specification +import scalaz.Scalaz.Id +import scalaz.data.{ ~>, ∀ } +import scalaz.parsers.Combinators._ + +class IsoOpsSpec extends Specification { + + private type TIso[A, B] = Iso[Id, Id, A, B] + + private val iso = new TIso[Int, String] { + override def to: UFV[Int, String] = _.toString + override def from: UGV[String, Int] = _.toInt + } + + implicit private val id: Id ~> Id = ∀.mk[Id ~> Id].from(identity) + + "Transforming Iso" >> { + "via reverse" in { + iso.to(1) must_=== (~iso).from(1) + iso.from("1") must_=== (~iso).to("1") + iso.to(1) must_=== (~(~iso)).to(1) + } + } +} From 875399b3cf52c17073701bcaa713aae657a66146 Mon Sep 17 00:00:00 2001 From: sergei-shabanau Date: Sat, 24 Nov 2018 22:01:48 -0500 Subject: [PATCH 2/2] #0 - `.scalafmt.conf` according to scalaz-sbt --- .scalafmt.conf | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index 5f8da63..33641c0 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -17,18 +17,10 @@ newlines { spaces { afterKeywordBeforeParen = true -// afterSymbolicDefs = true + afterSymbolicDefs = true inImportCurlyBraces = true } -//verticalMultiline { -// atDefnSite = true -// arityThreshold = 4 -// newlineAfterOpenParen = true -// newlineAfterImplicitKW = true -// newlineBeforeImplicitKW = false -//} - rewrite.rules = [ AsciiSortImports, AvoidInfix, @@ -36,4 +28,4 @@ rewrite.rules = [ RedundantBraces, RedundantParens, SortModifiers -] +] \ No newline at end of file