@@ -5,10 +5,6 @@ import arrow.core.NonEmptySet
5
5
import arrow.core.left
6
6
import arrow.core.nonEmptySetOf
7
7
import arrow.core.right
8
- import arrow.core.toNonEmptySetOrNull
9
- import kotlin.contracts.ExperimentalContracts
10
- import kotlin.contracts.InvocationKind
11
- import kotlin.contracts.contract
12
8
13
9
/* *
14
10
* A typealias for [Either] with [NonEmptySet] as the left side.
@@ -21,37 +17,16 @@ inline fun <A> A.rightNes(): EitherNes<Nothing, A> = this.right()
21
17
@Suppress(" NOTHING_TO_INLINE" )
22
18
inline fun <E > E.leftNes (): EitherNes <E , Nothing > = nonEmptySetOf(this ).left()
23
19
24
- @OptIn(ExperimentalContracts ::class )
25
20
inline fun <E , A , B , C , Z > Either.Companion.zipOrAccumulateNonEmptySet (
26
21
a : EitherNes <E , A >,
27
22
b : EitherNes <E , B >,
28
23
c : EitherNes <E , C >,
29
24
transform : (A , B , C ) -> Z ,
30
- ): EitherNes <E , Z > {
31
- contract { callsInPlace(transform, InvocationKind .AT_MOST_ONCE ) }
32
-
33
- return if (
34
- a is Either .Right &&
35
- b is Either .Right &&
36
- c is Either .Right
37
- ) {
38
- Either .Right (
39
- transform(
40
- a.value,
41
- b.value,
42
- c.value,
43
- ),
44
- )
45
- } else {
46
- Either .Left (
47
- buildSet(capacity = a.count + b.count + c.count) {
48
- if (a is Either .Left ) this .addAll(a.value)
49
- if (b is Either .Left ) this .addAll(b.value)
50
- if (c is Either .Left ) this .addAll(c.value)
51
- }.toNonEmptySetOrNull()!! ,
52
- )
53
- }
54
- }
55
-
56
- @PublishedApi
57
- internal inline val <L , R > Either <L , R >.count: Int get() = if (isRight()) 1 else 0
25
+ ): EitherNes <E , Z > =
26
+ zipOrAccumulate(
27
+ combine = { acc, value -> acc + value },
28
+ a = a,
29
+ b = b,
30
+ c = c,
31
+ transform = transform,
32
+ )
0 commit comments