Skip to content

Commit

Permalink
Merge pull request #116 from sagifogel/change_order_of_optics_composi…
Browse files Browse the repository at this point in the history
…tion

change compose/andThen to be aligned with function composition
  • Loading branch information
sagifogel authored Aug 13, 2021
2 parents aad47b7 + 398bc4a commit effbb98
Show file tree
Hide file tree
Showing 60 changed files with 1,644 additions and 1,638 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ and is built on top of [Cats](https://typelevel.org/cats/), and [Spire](https://
Add to your `build.sbt`
```scala
libraryDependencies ++= Seq(
"io.github.sagifogel" %% "proptics-core" % "0.3.0",
"io.github.sagifogel" %% "proptics-profunctor" % "0.3.0"
"io.github.sagifogel" %% "proptics-core" % "0.3.1",
"io.github.sagifogel" %% "proptics-profunctor" % "0.3.1"
)
```

Expand Down
164 changes: 82 additions & 82 deletions core/shared/src/main/scala/proptics/ALens.scala

Large diffs are not rendered by default.

170 changes: 85 additions & 85 deletions core/shared/src/main/scala/proptics/APrism.scala

Large diffs are not rendered by default.

156 changes: 78 additions & 78 deletions core/shared/src/main/scala/proptics/ATraversal.scala

Large diffs are not rendered by default.

156 changes: 78 additions & 78 deletions core/shared/src/main/scala/proptics/AffineTraversal.scala

Large diffs are not rendered by default.

156 changes: 78 additions & 78 deletions core/shared/src/main/scala/proptics/AnAffineTraversal.scala

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions core/shared/src/main/scala/proptics/AnIndexedLens.scala

Large diffs are not rendered by default.

178 changes: 89 additions & 89 deletions core/shared/src/main/scala/proptics/AnIso.scala

Large diffs are not rendered by default.

140 changes: 70 additions & 70 deletions core/shared/src/main/scala/proptics/Fold.scala

Large diffs are not rendered by default.

138 changes: 69 additions & 69 deletions core/shared/src/main/scala/proptics/Getter.scala

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions core/shared/src/main/scala/proptics/Grate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,68 +39,68 @@ abstract class Grate_[S, T, A, B] { self =>
/** synonym for [[cotraverse]], flipped */
final def zipWithF[F[_]: Applicative](f: F[A] => B)(fs: F[S]): T = cotraverse(fs)(f)

/** compose this [[Grate_]] with an [[Iso_]], having this [[Grate_]] applied last */
final def compose[C, D](other: Iso_[A, B, C, D]): Grate_[S, T, C, D] = new Grate_[S, T, C, D] {
/** compose this [[Grate_]] with an [[Iso_]], having this [[Grate_]] applied first */
final def andThen[C, D](other: Iso_[A, B, C, D]): Grate_[S, T, C, D] = new Grate_[S, T, C, D] {
override def apply[P[_, _]](pab: P[C, D])(implicit ev: Closed[P]): P[S, T] = self(other(pab))
}

/** compose this [[Grate_]] with an [[Iso_]], having this [[Grate_]] applied first */
final def andThen[C, D](other: Iso_[C, D, S, T]): Grate_[C, D, A, B] = new Grate_[C, D, A, B] {
/** compose this [[Grate_]] with an [[Iso_]], having this [[Grate_]] applied last */
final def compose[C, D](other: Iso_[C, D, S, T]): Grate_[C, D, A, B] = new Grate_[C, D, A, B] {
override private[proptics] def apply[P[_, _]](pab: P[A, B])(implicit ev: Closed[P]): P[C, D] =
other(self(pab))
}

/** compose this [[Grate_]] with an [[AnIso_]], having this [[Grate_]] applied last */
final def compose[C, D](other: AnIso_[A, B, C, D]): Grate_[S, T, C, D] = new Grate_[S, T, C, D] {
/** compose this [[Grate_]] with an [[AnIso_]], having this [[Grate_]] applied first */
final def andThen[C, D](other: AnIso_[A, B, C, D]): Grate_[S, T, C, D] = new Grate_[S, T, C, D] {
override def apply[P[_, _]](pab: P[C, D])(implicit ev: Closed[P]): P[S, T] =
self(ev.dimap(pab)(other.view)(other.review))
}

/** compose this [[Grate_]] with an [[AnIso_]], having this [[Grate_]] applied first */
final def andThen[C, D](other: AnIso_[C, D, S, T]): Grate_[C, D, A, B] = new Grate_[C, D, A, B] {
/** compose this [[Grate_]] with an [[AnIso_]], having this [[Grate_]] applied last */
final def compose[C, D](other: AnIso_[C, D, S, T]): Grate_[C, D, A, B] = new Grate_[C, D, A, B] {
override private[proptics] def apply[P[_, _]](pab: P[A, B])(implicit ev: Closed[P]): P[C, D] =
ev.dimap(self(pab))(other.view)(other.review)
}

/** compose this [[Grate_]] with a [[Setter_]], having this [[Grate_]] applied last */
final def compose[C, D](other: Setter_[A, B, C, D]): Setter_[S, T, C, D] = new Setter_[S, T, C, D] {
/** compose this [[Grate_]] with a [[Setter_]], having this [[Grate_]] applied first */
final def andThen[C, D](other: Setter_[A, B, C, D]): Setter_[S, T, C, D] = new Setter_[S, T, C, D] {
override private[proptics] def apply(pab: C => D): S => T = self(other(pab))
}

/** compose this [[Grate_]] with a [[Setter_]], having this [[Grate_]] applied first */
final def andThen[C, D](other: Setter_[C, D, S, T]): Setter_[C, D, A, B] = new Setter_[C, D, A, B] {
/** compose this [[Grate_]] with a [[Setter_]], having this [[Grate_]] applied last */
final def compose[C, D](other: Setter_[C, D, S, T]): Setter_[C, D, A, B] = new Setter_[C, D, A, B] {
override private[proptics] def apply(pab: A => B): C => D = other.over(self.over(pab))
}

/** compose this [[Grate_]] with a [[Grate_]], having this [[Grate_]] applied last */
final def compose[C, D](other: Grate_[A, B, C, D]): Grate_[S, T, C, D] = new Grate_[S, T, C, D] {
/** compose this [[Grate_]] with a [[Grate_]], having this [[Grate_]] applied first */
final def andThen[C, D](other: Grate_[A, B, C, D]): Grate_[S, T, C, D] = new Grate_[S, T, C, D] {
override def apply[P[_, _]](pab: P[C, D])(implicit ev: Closed[P]): P[S, T] = self(other(pab))
}

/** compose this [[Grate_]] with a [[Grate_]], having this [[Grate_]] applied first */
final def andThen[C, D](other: Grate_[C, D, S, T]): Grate_[C, D, A, B] = new Grate_[C, D, A, B] {
/** compose this [[Grate_]] with a [[Grate_]], having this [[Grate_]] applied last */
final def compose[C, D](other: Grate_[C, D, S, T]): Grate_[C, D, A, B] = new Grate_[C, D, A, B] {
override private[proptics] def apply[P[_, _]](pab: P[A, B])(implicit ev: Closed[P]): P[C, D] = other(self(pab))
}

/** compose this [[Grate_]] with a [[Review_]], having this [[Grate_]] applied last */
final def compose[C, D](other: Review_[A, B, C, D]): Review_[S, T, C, D] = new Review_[S, T, C, D] {
/** compose this [[Grate_]] with a [[Review_]], having this [[Grate_]] applied first */
final def andThen[C, D](other: Review_[A, B, C, D]): Review_[S, T, C, D] = new Review_[S, T, C, D] {
override private[proptics] def apply(tagged: Tagged[C, D]): Tagged[S, T] = self(other(tagged))
}

/** compose this [[Grate_]] with a [[Review_]], having this [[Grate_]] applied first */
final def andThen[C, D](other: Review_[C, D, S, T]): Review_[C, D, A, B] = new Review_[C, D, A, B] {
/** compose this [[Grate_]] with a [[Review_]], having this [[Grate_]] applied last */
final def compose[C, D](other: Review_[C, D, S, T]): Review_[C, D, A, B] = new Review_[C, D, A, B] {
override private[proptics] def apply(tagged: Tagged[A, B]): Tagged[C, D] =
Tagged(other.review(self.review(tagged.runTag)))
}

/** compose this [[Grate_]] with an [[IndexedSetter_]], having this [[Grate_]] applied last */
final def compose[I, C, D](other: IndexedSetter_[I, A, B, C, D]): IndexedSetter_[I, S, T, C, D] = new IndexedSetter_[I, S, T, C, D] {
/** compose this [[Grate_]] with an [[IndexedSetter_]], having this [[Grate_]] applied first */
final def andThen[I, C, D](other: IndexedSetter_[I, A, B, C, D]): IndexedSetter_[I, S, T, C, D] = new IndexedSetter_[I, S, T, C, D] {
override private[proptics] def apply(indexed: Indexed[* => *, I, C, D]): S => T =
self.over(other.over(indexed.runIndex))
}

/** compose this [[Grate_]] with an [[IndexedSetter_]], having this [[Grate_]] applied first */
final def andThen[I, C, D](other: IndexedSetter_[I, C, D, S, T]): IndexedSetter_[I, C, D, A, B] = new IndexedSetter_[I, C, D, A, B] {
/** compose this [[Grate_]] with an [[IndexedSetter_]], having this [[Grate_]] applied last */
final def compose[I, C, D](other: IndexedSetter_[I, C, D, S, T]): IndexedSetter_[I, C, D, A, B] = new IndexedSetter_[I, C, D, A, B] {
override private[proptics] def apply(indexed: Indexed[* => *, I, A, B]): C => D =
other.over { case (s, i) => self.over(a => indexed.runIndex((a, i)))(s) }
}
Expand Down
Loading

0 comments on commit effbb98

Please sign in to comment.