Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identity both for vector. #1454

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
)
)
}
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