Skip to content

Commit

Permalink
Remove Cause
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostdogpr committed Dec 27, 2024
1 parent c567bfc commit 1bf899d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 40 deletions.
18 changes: 10 additions & 8 deletions core/shared/src/main/scala/zio/prelude/Associative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1453,15 +1453,17 @@ object Associative extends AssociativeLowPriority {

trait AssociativeLowPriority {

implicit def FxCauseProdAssociative[A]: Associative[Prod[fx.Cause[A]]] = new Associative[Prod[fx.Cause[A]]] {
def combine(l: => Prod[fx.Cause[A]], r: => Prod[fx.Cause[A]]): Prod[fx.Cause[A]] =
Prod(Prod.unwrap(l) ++ Prod.unwrap(r))
}
implicit def parSeqProdAssociative[A]: Associative[Prod[ParSeq[Unit, A]]] =
new Associative[Prod[ParSeq[Unit, A]]] {
def combine(l: => Prod[ParSeq[Unit, A]], r: => Prod[ParSeq[Unit, A]]): Prod[ParSeq[Unit, A]] =
Prod(Prod.unwrap(l) ++ Prod.unwrap(r))
}

implicit def FxCauseSumCommutative[A]: Commutative[Sum[fx.Cause[A]]] = new Commutative[Sum[fx.Cause[A]]] {
def combine(l: => Sum[fx.Cause[A]], r: => Sum[fx.Cause[A]]): Sum[fx.Cause[A]] =
Sum(Sum.unwrap(l) && Sum.unwrap(r))
}
implicit def parSeqSumCommutative[A]: Commutative[Sum[ParSeq[Unit, A]]] =
new Commutative[Sum[ParSeq[Unit, A]]] {
def combine(l: => Sum[ParSeq[Unit, A]], r: => Sum[ParSeq[Unit, A]]): Sum[ParSeq[Unit, A]] =
Sum(Sum.unwrap(l) && Sum.unwrap(r))
}

/**
* The `Commutative` and `PartialInverse` instance for the product of `Int` values.
Expand Down
22 changes: 0 additions & 22 deletions core/shared/src/main/scala/zio/prelude/fx/package.scala

This file was deleted.

1 change: 0 additions & 1 deletion docs/functional-abstractions/abstraction-diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ classDiagram
DistributiveProd~A~ <|-- Annihilation~A~
class DistributiveProd~A~{
Cause[A]
fx.Cause[A]
ParSeq[Unit, A]
() Sum: Associative[Sum[A]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ object DistributiveProd extends DistributiveProdLowPriorityImplicits {

trait DistributiveProdLowPriorityImplicits {

implicit def FxCauseDistributiveProd[A]: DistributiveProd[fx.Cause[A]] =
new DistributiveProd[fx.Cause[A]] {
val Sum: Associative[Sum[fx.Cause[A]]] = Associative.FxCauseSumCommutative
val Prod: Associative[Prod[fx.Cause[A]]] = Associative.FxCauseProdAssociative
implicit def parSeqDistributiveProd[A]: DistributiveProd[ParSeq[Unit, A]] =
new DistributiveProd[ParSeq[Unit, A]] {
val Sum: Associative[Sum[ParSeq[Unit, A]]] = Associative.parSeqSumCommutative
val Prod: Associative[Prod[ParSeq[Unit, A]]] = Associative.parSeqProdAssociative
}

}
Expand Down
9 changes: 4 additions & 5 deletions laws/shared/src/main/scala/zio/prelude/laws/Gens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package zio.prelude.laws

import zio.Trace
import zio.prelude._
import zio.prelude.fx.Cause
import zio.prelude.newtypes.Natural
import zio.test._

Expand All @@ -41,23 +40,23 @@ object Gens {
Gen.int(min, max).map(Natural.unsafeMake)

def parSeq[R <: Sized, Z <: Unit, A](z: Gen[R, Z], a: Gen[R, A]): Gen[R, ParSeq[Z, A]] = {
val failure = a.map(Cause.single)
val empty = z.map(_ => Cause.empty.asInstanceOf[ParSeq[Nothing, Nothing]])
val failure = a.map(ParSeq.single)
val empty = z.map(_ => ParSeq.empty.asInstanceOf[ParSeq[Nothing, Nothing]])

def sequential(n: Int) = Gen.suspend {
for {
i <- Gen.int(1, n - 1)
l <- parSeqN(i)
r <- parSeqN(n - i)
} yield Cause.Then(l, r)
} yield ParSeq.Then(l, r)
}

def parallel(n: Int) = Gen.suspend {
for {
i <- Gen.int(1, n - 1)
l <- parSeqN(i)
r <- parSeqN(n - i)
} yield Cause.Both(l, r)
} yield ParSeq.Both(l, r)
}

def parSeqN(n: Int): Gen[R, ParSeq[Z, A]] = Gen.suspend {
Expand Down

0 comments on commit 1bf899d

Please sign in to comment.