Skip to content

Commit 9e18c06

Browse files
authored
Fixed #269 - Add DivariantSyntax and DivariantOps (#270)
1 parent 62bd4c9 commit 9e18c06

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/main/scala/zio/prelude/Divariant.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,20 @@ object Divariant {
3131
}
3232
}
3333
}
34+
35+
trait DivariantSyntax {
36+
37+
implicit class DivariantOps[:=>[-_, +_], A, B](f: => A :=> B) {
38+
39+
def dimap[C, D](g: C => A, h: B => D)(implicit divariant: Divariant[:=>]): C :=> D =
40+
divariant.dimap(g, h)(f)
41+
42+
def leftMap[C](ca: C => A)(implicit divariant: Divariant[:=>]): C :=> B =
43+
divariant.leftMap(ca)(f)
44+
45+
def rightMap[C](bc: B => C)(implicit divariant: Divariant[:=>]): A :=> C =
46+
divariant.rightMap(bc)(f)
47+
48+
}
49+
50+
}

src/main/scala/zio/prelude/package.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package object prelude
1616
with CovariantSyntax
1717
with ContravariantSyntax
1818
with DebugSyntax
19+
with DivariantSyntax
1920
with EqualSyntax
2021
with HashSyntax
2122
with IdExports

0 commit comments

Comments
 (0)