From 4d9fdef15d182a00cb8ebbf7df1af186cb2b9d3c Mon Sep 17 00:00:00 2001 From: SimY4 Date: Wed, 15 Jan 2025 21:25:18 +1100 Subject: [PATCH 1/2] identity both for vector. --- .../src/test/scala/zio/prelude/IdentityBothSpec.scala | 3 ++- .../src/main/scala/zio/prelude/AssociativeBoth.scala | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core-tests/shared/src/test/scala/zio/prelude/IdentityBothSpec.scala b/core-tests/shared/src/test/scala/zio/prelude/IdentityBothSpec.scala index 28d121632..46e2fb880 100644 --- a/core-tests/shared/src/test/scala/zio/prelude/IdentityBothSpec.scala +++ b/core-tests/shared/src/test/scala/zio/prelude/IdentityBothSpec.scala @@ -14,7 +14,8 @@ object IdentityBothSpec extends ZIOBaseSpec { test("list")(checkAllLaws(IdentityBothLaws)(GenF.list, Gen.int)), test("option")(checkAllLaws(IdentityBothLaws)(GenF.option, Gen.int)), test("optional")(checkAllLaws(IdentityBothLaws)(optionalGenF, Gen.int)), - test("try")(checkAllLaws(IdentityBothLaws)(GenFs.tryScala, Gen.int)) + test("try")(checkAllLaws(IdentityBothLaws)(GenFs.tryScala, Gen.int)), + test("vector")(checkAllLaws(IdentityBothLaws)(GenF.vector, Gen.int)) ) ) } diff --git a/core/shared/src/main/scala/zio/prelude/AssociativeBoth.scala b/core/shared/src/main/scala/zio/prelude/AssociativeBoth.scala index f52959525..e643d2a57 100644 --- a/core/shared/src/main/scala/zio/prelude/AssociativeBoth.scala +++ b/core/shared/src/main/scala/zio/prelude/AssociativeBoth.scala @@ -1389,10 +1389,11 @@ object AssociativeBoth extends AssociativeBothLowPriority { } /** - * The `AssociativeBoth` instance for `Vector`. + * The `IdentityBoth` (and `AssociativeBoth`) instance for `Vector`. */ - implicit val VectorAssociativeBoth: AssociativeBoth[Vector] = - new AssociativeBoth[Vector] { + implicit val VectorIdentityBoth: IdentityBoth[Vector] = + new IdentityBoth[Vector] { + def any: Vector[Any] = Vector(()) def both[A, B](fa: => Vector[A], fb: => Vector[B]): Vector[(A, B)] = fa.flatMap(a => fb.map(b => (a, b))) } From e157ca2bd71968c4388e6280b12ae15b783e0890 Mon Sep 17 00:00:00 2001 From: SimY4 Date: Thu, 16 Jan 2025 07:52:17 +1100 Subject: [PATCH 2/2] Update abstraction diagrams --- .../abstraction-diagrams.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/functional-abstractions/abstraction-diagrams.md b/docs/functional-abstractions/abstraction-diagrams.md index c38a9f719..722c2983d 100644 --- a/docs/functional-abstractions/abstraction-diagrams.md +++ b/docs/functional-abstractions/abstraction-diagrams.md @@ -155,8 +155,11 @@ classDiagram AssociativeBoth~F<_>~ <|-- CommutativeBoth~F<_>~ AssociativeBoth~F<_>~ <|-- IdentityBoth~F<_>~ class AssociativeBoth~F<_>~{ + Exit[E, +*] Fiber[E, +*] - STM[R, E, +*] + NonEmptyChunk[+*] + ZSink[R, E, I, L, +*] + ZStream[R, E, +*] () both[A,B](=> F[A], => F[B]): F[(A,B)] } @@ -175,18 +178,23 @@ classDiagram ZLayer[R, E, +*] ZManaged[R, E, +*] Failure[ZManaged[R, E, +*]] - ZSink[R, E, I, I, +*] + ZSink[R, E, I, L, +*] ZStream[R, E, +*] } class IdentityBoth~F<_>~{ + Chunk[+*] + Config[+*] Either[L, +*] Failure[Either[+*, R]] Option[+*] + Optional[+*] Future[+*] Id[+*] List[+*] + STM[R, E, +*] Try[+*] - + Vector[+*] + () any: F[Any] } ```