Skip to content

Commit

Permalink
identity both for vector. (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimY4 authored Jan 17, 2025
1 parent e4df3ab commit 7d074d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
)
}
7 changes: 4 additions & 3 deletions core/shared/src/main/scala/zio/prelude/AssociativeBoth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

Expand Down
14 changes: 11 additions & 3 deletions docs/functional-abstractions/abstraction-diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
}
Expand All @@ -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]
}
```
Expand Down

0 comments on commit 7d074d2

Please sign in to comment.