16
16
17
17
package zio .prelude .fx
18
18
19
+ import zio ._
19
20
import zio .prelude ._
20
21
import zio .prelude .coherent .CovariantIdentityBoth
21
- import zio .{Cause => _ , _ }
22
22
23
23
import java .util .concurrent .atomic .AtomicBoolean
24
24
import scala .reflect .ClassTag
@@ -36,36 +36,12 @@ import scala.util.Try
36
36
sealed trait ZPure [+ W , - S1 , + S2 , - R , + E , + A ] { self =>
37
37
import ZPure ._
38
38
39
- /**
40
- * A symbolic alias for `zipParRight`.
41
- */
42
- final def &> [W1 >: W , S3 >: S2 <: S1 , R1 <: R , E1 >: E , B , C ](
43
- that : ZPure [W1 , S3 , S3 , R1 , E1 , B ]
44
- ): ZPure [W1 , S3 , S3 , R1 , E1 , B ] =
45
- self zipParRight that
46
-
47
39
/**
48
40
* A symbolic alias for `zipRight`.
49
41
*/
50
42
final def *> [W1 >: W , S3 , R1 <: R , E1 >: E , B ](that : ZPure [W1 , S2 , S3 , R1 , E1 , B ]): ZPure [W1 , S1 , S3 , R1 , E1 , B ] =
51
43
self zipRight that
52
44
53
- /**
54
- * A symbolic alias for `zipParLeft`.
55
- */
56
- final def <& [W1 >: W , S3 >: S2 <: S1 , R1 <: R , E1 >: E , B , C ](
57
- that : ZPure [W1 , S3 , S3 , R1 , E1 , B ]
58
- ): ZPure [W1 , S3 , S3 , R1 , E1 , A ] =
59
- self zipParLeft that
60
-
61
- /**
62
- * A symbolic alias for `zipPar`.
63
- */
64
- final def <&> [W1 >: W , S3 >: S2 <: S1 , R1 <: R , E1 >: E , B , C ](that : ZPure [W1 , S3 , S3 , R1 , E1 , B ])(implicit
65
- zippable : Zippable [A , B ]
66
- ): ZPure [W1 , S3 , S3 , R1 , E1 , zippable.Out ] =
67
- self zipPar that
68
-
69
45
/**
70
46
* A symbolic alias for `zipLeft`.
71
47
*/
@@ -263,12 +239,6 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
263
239
): ZPure [W , S3 , S3 , R , Nothing , B ] =
264
240
self.foldM(e => ZPure .succeed(failure(e)), a => ZPure .succeed(success(a)))
265
241
266
- final def foldCauseM [W1 >: W , S0 <: S1 , S3 , R1 <: R , E1 , B ](
267
- failure : Cause [E ] => ZPure [W1 , S0 , S3 , R1 , E1 , B ],
268
- success : A => ZPure [W1 , S2 , S3 , R1 , E1 , B ]
269
- )(implicit ev : CanFail [E ]): ZPure [W1 , S0 , S3 , R1 , E1 , B ] =
270
- Fold (self, failure, success)
271
-
272
242
/**
273
243
* Recovers from errors by accepting one computation to execute for the case
274
244
* of an error, and one computation to execute for the case of success.
@@ -277,7 +247,7 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
277
247
failure : E => ZPure [W1 , S0 , S3 , R1 , E1 , B ],
278
248
success : A => ZPure [W1 , S2 , S3 , R1 , E1 , B ]
279
249
)(implicit ev : CanFail [E ]): ZPure [W1 , S0 , S3 , R1 , E1 , B ] =
280
- foldCauseM(( cause : Cause [ E ]) => failure(cause.first) , success)
250
+ Fold (self, failure, success)
281
251
282
252
/**
283
253
* Exposes the output state into the value channel.
@@ -361,14 +331,6 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
361
331
final def mapError [E1 ](f : E => E1 )(implicit ev : CanFail [E ]): ZPure [W , S1 , S2 , R , E1 , A ] =
362
332
catchAll(e => fail(f(e)))
363
333
364
- /**
365
- * Returns a computation with its full cause of failure mapped using the
366
- * specified function. This can be users to transform errors while
367
- * preserving the original structure of the `Cause`.
368
- */
369
- final def mapErrorCause [E2 ](f : Cause [E ] => Cause [E2 ]): ZPure [W , S1 , S2 , R , E2 , A ] =
370
- foldCauseM(cause => ZPure .failCause(f(cause)), ZPure .succeed)
371
-
372
334
/**
373
335
* Transforms the updated state of this computation with the specified
374
336
* function.
@@ -578,29 +540,29 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
578
540
* the updated state and the result.
579
541
*/
580
542
final def run (s : S1 )(implicit ev1 : Any <:< R , ev2 : E <:< Nothing ): (S2 , A ) =
581
- runAll(s)._2.fold(cause => ev2(cause.first) , identity)
543
+ runAll(s)._2.fold(ev2, identity)
582
544
583
545
/**
584
546
* Runs this computation with the specified initial state, returning both the
585
547
* log and either all the failures that occurred or the updated state and the
586
548
* result.
587
549
*/
588
- final def runAll (s : S1 )(implicit ev : Any <:< R ): (Chunk [W ], Either [Cause [ E ] , (S2 , A )]) =
550
+ final def runAll (s : S1 )(implicit ev : Any <:< R ): (Chunk [W ], Either [E , (S2 , A )]) =
589
551
Runner (s, self)
590
552
591
553
/**
592
554
* Runs this computation to produce its result or the first failure to
593
555
* occur.
594
556
*/
595
557
final def runEither (implicit ev1 : Unit <:< S1 , ev2 : Any <:< R ): Either [E , A ] =
596
- runAll(())._2.fold(cause => Left (cause.first ), { case (_, a) => Right (a) })
558
+ runAll(())._2.fold(error => Left (error ), { case (_, a) => Right (a) })
597
559
598
560
/**
599
561
* Runs this computation to produce its result and the log.
600
562
*/
601
563
final def runLog (implicit ev1 : Unit <:< S1 , ev2 : Any <:< R , ev3 : E <:< Nothing ): (Chunk [W ], A ) = {
602
564
val (log, either) = runAll(())
603
- (log, either.fold(cause => ev3(cause.first ), { case (_, a) => a }))
565
+ (log, either.fold(error => ev3(error ), { case (_, a) => a }))
604
566
}
605
567
606
568
/**
@@ -622,16 +584,10 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
622
584
*/
623
585
final def runValidation (implicit ev1 : Unit <:< S1 , ev2 : Any <:< R ): ZValidation [W , E , A ] =
624
586
runAll(()) match {
625
- case (log, Left (cause )) => ZValidation .Failure (log, NonEmptyChunk .fromChunk(cause.toChunk).get )
587
+ case (log, Left (error )) => ZValidation .Failure (log, NonEmptyChunk .single(error) )
626
588
case (log, Right ((_, a))) => ZValidation .Success (log, a)
627
589
}
628
590
629
- /**
630
- * Exposes the full cause of failures of this computation.
631
- */
632
- final def sandbox : ZPure [W , S1 , S2 , R , Cause [E ], A ] =
633
- foldCauseM(ZPure .fail, ZPure .succeed)
634
-
635
591
/**
636
592
* Converts an option on values into an option on errors leaving the state unchanged.
637
593
*/
@@ -684,7 +640,7 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
684
640
def toZIO (implicit ev : Unit <:< S1 ): zio.ZIO [R , E , A ] =
685
641
ZIO .environmentWithZIO[R ] { r =>
686
642
provideEnvironment(r).runAll(())._2 match {
687
- case Left (cause ) => ZIO .failCause(cause.toCause )
643
+ case Left (error ) => ZIO .fail(error )
688
644
case Right ((_, a)) => ZIO .succeed(a)
689
645
}
690
646
}
@@ -696,7 +652,7 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
696
652
ZIO .environmentWithZIO[R ] { r =>
697
653
val result = provideEnvironment(r).runAll(s1)
698
654
result._2 match {
699
- case Left (cause ) => ZIO .failCause(cause.toCause )
655
+ case Left (error ) => ZIO .fail(error )
700
656
case Right ((_, a)) => ZIO .succeed(a)
701
657
}
702
658
}
@@ -708,7 +664,7 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
708
664
ZIO .environmentWithZIO[R ] { r =>
709
665
val result = provideEnvironment(r).runAll(s1)
710
666
result._2 match {
711
- case Left (cause ) => ZIO .failCause(cause.toCause )
667
+ case Left (error ) => ZIO .fail(error )
712
668
case Right (result) => ZIO .succeed(result)
713
669
}
714
670
}
@@ -720,17 +676,11 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
720
676
ZIO .environmentWithZIO[R ] { r =>
721
677
val (log, result) = provideEnvironment(r).runAll(s1)
722
678
result match {
723
- case Left (cause ) => ZIO .failCause(cause.toCause )
679
+ case Left (error ) => ZIO .fail(error )
724
680
case Right ((s2, a)) => ZIO .succeed((log, s2, a))
725
681
}
726
682
}
727
683
728
- /**
729
- * Submerges the full cause of failures of this computation.
730
- */
731
- def unsandbox [E1 ](implicit ev : E <:< Cause [E1 ]): ZPure [W , S1 , S2 , R , E1 , A ] =
732
- foldM(e => ZPure .failCause(ev(e)), a => ZPure .succeed(a))
733
-
734
684
/**
735
685
* Combines this computation with the specified computation, passing the
736
686
* updated state from this computation to that computation and combining the
@@ -771,33 +721,6 @@ sealed trait ZPure[+W, -S1, +S2, -R, +E, +A] { self =>
771
721
)(f : (A , B ) => C ): ZPure [W1 , S1 , S3 , R1 , E1 , C ] =
772
722
self.flatMap(a => that.map(b => f(a, b)))
773
723
774
- final def zipWithPar [W1 >: W , S3 >: S2 <: S1 , R1 <: R , E1 >: E , B , C ](
775
- that : ZPure [W1 , S3 , S3 , R1 , E1 , B ]
776
- )(f : (A , B ) => C ): ZPure [W1 , S3 , S3 , R1 , E1 , C ] =
777
- self.foldCauseM(
778
- c1 =>
779
- that.foldCauseM(
780
- c2 => ZPure .failCause(c1 && c2),
781
- _ => ZPure .failCause(c1)
782
- ),
783
- a => that.map(b => f(a, b))
784
- )
785
-
786
- final def zipPar [W1 >: W , S3 >: S2 <: S1 , R1 <: R , E1 >: E , B , C ](that : ZPure [W1 , S3 , S3 , R1 , E1 , B ])(implicit
787
- zippable : Zippable [A , B ]
788
- ): ZPure [W1 , S3 , S3 , R1 , E1 , zippable.Out ] =
789
- self.zipWithPar(that)(zippable.zip(_, _))
790
-
791
- final def zipParLeft [W1 >: W , S3 >: S2 <: S1 , R1 <: R , E1 >: E , B , C ](
792
- that : ZPure [W1 , S3 , S3 , R1 , E1 , B ]
793
- ): ZPure [W1 , S3 , S3 , R1 , E1 , A ] =
794
- self.zipWithPar(that)((a, _) => a)
795
-
796
- final def zipParRight [W1 >: W , S3 >: S2 <: S1 , R1 <: R , E1 >: E , B , C ](
797
- that : ZPure [W1 , S3 , S3 , R1 , E1 , B ]
798
- ): ZPure [W1 , S3 , S3 , R1 , E1 , B ] =
799
- self.zipWithPar(that)((_, b) => b)
800
-
801
724
/**
802
725
* Returns a successful computation if the value is `Right`, or fails with error `None`.
803
726
*/
@@ -915,10 +838,7 @@ object ZPure {
915
838
new EnvironmentWithPurePartiallyApplied
916
839
917
840
def fail [E ](e : E ): ZPure [Nothing , Any , Nothing , Any , E , Nothing ] =
918
- failCause(Cause (e))
919
-
920
- def failCause [E ](cause : Cause [E ]): ZPure [Nothing , Any , Nothing , Any , E , Nothing ] =
921
- ZPure .Fail (cause)
841
+ ZPure .Fail (e)
922
842
923
843
/**
924
844
* Constructs a computation from an `Either`.
@@ -1183,15 +1103,15 @@ object ZPure {
1183
1103
}
1184
1104
1185
1105
private final case class Succeed [+ A ](value : A ) extends ZPure [Nothing , Any , Nothing , Any , Nothing , A ]
1186
- private final case class Fail [+ E ](error : Cause [ E ]) extends ZPure [Nothing , Any , Nothing , Any , E , Nothing ]
1106
+ private final case class Fail [+ E ](error : E ) extends ZPure [Nothing , Any , Nothing , Any , E , Nothing ]
1187
1107
private final case class Modify [- S1 , + S2 , + A ](run0 : S1 => (A , S2 )) extends ZPure [Nothing , S1 , S2 , Any , Nothing , A ]
1188
1108
private final case class FlatMap [+ W , - S1 , S2 , + S3 , - R , + E , A , + B ](
1189
1109
value : ZPure [W , S1 , S2 , R , E , A ],
1190
1110
continue : A => ZPure [W , S2 , S3 , R , E , B ]
1191
1111
) extends ZPure [W , S1 , S3 , R , E , B ]
1192
1112
private final case class Fold [+ W , - S1 , S2 , + S3 , - R , E1 , + E2 , A , + B ](
1193
1113
value : ZPure [W , S1 , S2 , R , E1 , A ],
1194
- failure : Cause [ E1 ] => ZPure [W , S1 , S3 , R , E2 , B ],
1114
+ failure : E1 => ZPure [W , S1 , S3 , R , E2 , B ],
1195
1115
success : A => ZPure [W , S2 , S3 , R , E2 , B ]
1196
1116
) extends ZPure [W , S1 , S3 , R , E2 , B ]
1197
1117
with Function [A , ZPure [W , S2 , S3 , R , E2 , B ]] {
@@ -1222,7 +1142,7 @@ object ZPure {
1222
1142
def apply [W , S1 , S2 , R , E , A ](
1223
1143
state : S1 ,
1224
1144
zPure : ZPure [W , S1 , S2 , R , E , A ]
1225
- ): (Chunk [W ], Either [Cause [ E ] , (S2 , A )]) = {
1145
+ ): (Chunk [W ], Either [E , (S2 , A )]) = {
1226
1146
val (runner, running) = pool.get()
1227
1147
1228
1148
if (running.compareAndSet(false , true )) {
@@ -1237,7 +1157,7 @@ object ZPure {
1237
1157
}
1238
1158
}
1239
1159
1240
- final private case class Err (cause : Cause [ Any ] ) extends Exception {
1160
+ final private case class Err (cause : Any ) extends Exception {
1241
1161
override def fillInStackTrace (): Throwable = this
1242
1162
}
1243
1163
}
@@ -1261,12 +1181,12 @@ object ZPure {
1261
1181
private def run [W , S1 , S2 , R , E , A ](
1262
1182
state : S1 ,
1263
1183
zPure : ZPure [W , S1 , S2 , R , E , A ]
1264
- ): (Chunk [W ], Either [Cause [ E ] , (S2 , A )]) = {
1184
+ ): (Chunk [W ], Either [E , (S2 , A )]) = {
1265
1185
val result =
1266
1186
try
1267
1187
Right (loop(state, zPure.asInstanceOf [Erased ]))
1268
1188
catch {
1269
- case Runner .Err (c) => Left (c.asInstanceOf [Cause [ E ] ])
1189
+ case Runner .Err (c) => Left (c.asInstanceOf [E ])
1270
1190
}
1271
1191
1272
1192
(_logs.result().asInstanceOf [Chunk [W ]], result)
@@ -1326,9 +1246,9 @@ object ZPure {
1326
1246
1327
1247
ZPure .Fold (
1328
1248
zPure.value,
1329
- (cause : Cause [ Any ] ) => {
1249
+ (error : Any ) => {
1330
1250
_logs = previousLogs
1331
- ZPure .set(state) *> zPure.failure(cause )
1251
+ ZPure .set(state) *> zPure.failure(error )
1332
1252
},
1333
1253
(a : Any ) => {
1334
1254
val logs0 = _logs.result()
@@ -1340,7 +1260,7 @@ object ZPure {
1340
1260
} else {
1341
1261
ZPure .Fold (
1342
1262
zPure.value,
1343
- ZPure .set(state) *> zPure.failure(_ : Cause [ Any ] ),
1263
+ ZPure .set(state) *> zPure.failure(_ : Any ),
1344
1264
zPure.success
1345
1265
)
1346
1266
}
@@ -1359,8 +1279,8 @@ object ZPure {
1359
1279
val zPure = provide0.asInstanceOf [Provide [Any , Any , Any , Any , Any , Any ]]
1360
1280
val previousEnv = _environment
1361
1281
_environment = zPure.r
1362
- curZPure = zPure.continue.foldCauseM (
1363
- e => { _environment = previousEnv; ZPure .failCause (e) },
1282
+ curZPure = zPure.continue.foldM (
1283
+ e => { _environment = previousEnv; ZPure .fail (e) },
1364
1284
a => { _environment = previousEnv; ZPure .succeed(a) }
1365
1285
)
1366
1286
0 commit comments