From ebd1bd4a5979da123598c4a5f9302e32d3edd5aa Mon Sep 17 00:00:00 2001 From: Adam Fraser Date: Fri, 15 Sep 2023 21:34:21 -0700 Subject: [PATCH 1/2] fix covariantidentityboth#foreach implementation --- .../shared/src/test/scala/zio/prelude/CoherentSpec.scala | 4 ++++ .../src/main/scala/zio/prelude/coherent/coherent.scala | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core-tests/shared/src/test/scala/zio/prelude/CoherentSpec.scala b/core-tests/shared/src/test/scala/zio/prelude/CoherentSpec.scala index 28329726b..e799ada1c 100644 --- a/core-tests/shared/src/test/scala/zio/prelude/CoherentSpec.scala +++ b/core-tests/shared/src/test/scala/zio/prelude/CoherentSpec.scala @@ -51,6 +51,10 @@ object CoherentSpec extends ZIOBaseSpec { assert(instance.multiplyOption(5)(Sum(2)))(equalTo[Option[Sum[Int]]](Some(Sum(10)))) && assert(instance.multiplyOption(0)(Sum(2)))(equalTo[Option[Sum[Int]]](Some(Sum(0)))) && assert(instance.multiplyOption(-5)(Sum(2)))(equalTo[Option[Sum[Int]]](Some(Sum(-10)))) + }, + test("CovariantIdentityBoth") { + val instance = implicitly[CovariantIdentityBoth[List]] + assert(instance.forEach(List(List(1, 2), List(3)))(identity))(equalTo(List(List(1, 3), List(2, 3)))) } ) } diff --git a/core/shared/src/main/scala/zio/prelude/coherent/coherent.scala b/core/shared/src/main/scala/zio/prelude/coherent/coherent.scala index 1c3bb2fc0..7ab57335b 100644 --- a/core/shared/src/main/scala/zio/prelude/coherent/coherent.scala +++ b/core/shared/src/main/scala/zio/prelude/coherent/coherent.scala @@ -185,7 +185,11 @@ trait CovariantIdentityBoth[F[+_]] extends Covariant[F] with IdentityBoth[F] { s def forEach[A, B, Collection[+Element] <: Iterable[Element]](in: Collection[A])(f: A => F[B])(implicit bf: BuildFrom[Collection[A], B, Collection[B]] ): F[Collection[B]] = - in.foldLeft(bf.newBuilder(in).succeed)((bs, a) => bs.zipWith(f(a))(_ += _)).map(_.result()) + in.foldLeft(List.empty[B].succeed)((fbs, a) => fbs.zipWith(f(a))((bs, b) => b :: bs)).map { bs => + val builder = bf.newBuilder(in) + builder ++= bs.reverse + builder.result() + } def forEach_[A, B](in: Iterable[A])(f: A => F[Any]): F[Unit] = in.foldLeft(identityBoth.any)((bs, a) => bs *> f(a)).unit From bcf65ede21ab916730b5589d03d82dd9026ce8de Mon Sep 17 00:00:00 2001 From: Adam Fraser Date: Fri, 15 Sep 2023 21:44:47 -0700 Subject: [PATCH 2/2] update --- .github/workflows/site.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml index ed4467ae3..e34f7a7b1 100644 --- a/.github/workflows/site.yml +++ b/.github/workflows/site.yml @@ -18,7 +18,7 @@ jobs: if: ${{ github.event_name == 'pull_request' }} steps: - name: Git Checkout - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v3.3.0 with: fetch-depth: '0' - name: Setup Scala @@ -39,7 +39,7 @@ jobs: if: ${{ ((github.event_name == 'release') && (github.event.action == 'published')) || (github.event_name == 'workflow_dispatch') }} steps: - name: Git Checkout - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v3.3.0 with: fetch-depth: '0' - name: Setup Scala @@ -63,7 +63,7 @@ jobs: if: ${{ (github.event_name == 'push') || ((github.event_name == 'release') && (github.event.action == 'published')) }} steps: - name: Git Checkout - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v3.3.0 with: ref: ${{ github.head_ref }} fetch-depth: '0'