@@ -5,10 +5,6 @@ import arrow.core.NonEmptySet
55import arrow.core.left
66import arrow.core.nonEmptySetOf
77import arrow.core.right
8- import arrow.core.toNonEmptySetOrNull
9- import kotlin.contracts.ExperimentalContracts
10- import kotlin.contracts.InvocationKind
11- import kotlin.contracts.contract
128
139/* *
1410 * A typealias for [Either] with [NonEmptySet] as the left side.
@@ -21,37 +17,16 @@ inline fun <A> A.rightNes(): EitherNes<Nothing, A> = this.right()
2117@Suppress(" NOTHING_TO_INLINE" )
2218inline fun <E > E.leftNes (): EitherNes <E , Nothing > = nonEmptySetOf(this ).left()
2319
24- @OptIn(ExperimentalContracts ::class )
2520inline fun <E , A , B , C , Z > Either.Companion.zipOrAccumulateNonEmptySet (
2621 a : EitherNes <E , A >,
2722 b : EitherNes <E , B >,
2823 c : EitherNes <E , C >,
2924 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