Skip to content

Commit e14d5eb

Browse files
raulrajai-walker
andauthored
Adds deprecated bind operators to Effect impls (#266)
Co-authored-by: Imran Settuba <[email protected]>
1 parent 69cee69 commit e14d5eb

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package arrow.core.computations
2+
3+
import arrow.continuations.Effect
4+
import arrow.core.Const
5+
import arrow.core.const
6+
import kotlin.coroutines.RestrictsSuspension
7+
8+
@Deprecated(
9+
"Const binding does not require suspension and this computation block will be removed."
10+
)
11+
fun interface ConstEffect<A, T> : Effect<Const<A, T>> {
12+
13+
@Deprecated("The monadic operator for the Arrow 1.x series will become invoke in 0.13", ReplaceWith("()"))
14+
suspend fun <B> Const<A, B>.bind(): B = this()
15+
16+
@Deprecated("The monadic operator for the Arrow 1.x series will become invoke in 0.13", ReplaceWith("()"))
17+
suspend operator fun <B> Const<A, B>.not(): B = this()
18+
19+
suspend operator fun <B> Const<A, B>.invoke(): B =
20+
value() as B
21+
}
22+
23+
@Deprecated(
24+
"Const binding does not require suspension and this computation block will be removed."
25+
)
26+
@RestrictsSuspension
27+
fun interface RestrictedConstEffect<E, A> : ConstEffect<E, A>
28+
29+
@Suppress("ClassName")
30+
@Deprecated(
31+
"Const binding does not require suspension and this computation block will be removed."
32+
)
33+
object const {
34+
inline fun <A, T> eager(crossinline c: suspend RestrictedConstEffect<A, *>.() -> A): Const<A, T> =
35+
Effect.restricted(eff = { RestrictedConstEffect { it } }, f = c, just = { it.const() })
36+
37+
suspend inline operator fun <A, T> invoke(crossinline c: suspend ConstEffect<A, *>.() -> A): Const<A, T> =
38+
Effect.suspended(eff = { ConstEffect { it } }, f = c, just = { it.const() })
39+
}

arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/either.kt

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import arrow.core.right
88
import kotlin.coroutines.RestrictsSuspension
99

1010
fun interface EitherEffect<E, A> : Effect<Either<E, A>> {
11+
12+
@Deprecated("The monadic operator for the Arrow 1.x series will become invoke in 0.13", ReplaceWith("()"))
13+
suspend fun <B> Either<E, B>.bind(): B = this()
14+
15+
@Deprecated("The monadic operator for the Arrow 1.x series will become invoke in 0.13", ReplaceWith("()"))
16+
suspend operator fun <B> Either<E, B>.not(): B = this()
17+
1118
suspend operator fun <B> Either<E, B>.invoke(): B =
1219
when (this) {
1320
is Either.Right -> b
@@ -22,13 +29,7 @@ fun interface EitherEffect<E, A> : Effect<Either<E, A>> {
2229
}
2330

2431
@RestrictsSuspension
25-
fun interface RestrictedEitherEffect<E, A> : Effect<Either<E, A>> {
26-
suspend operator fun <B> Either<E, B>.invoke(): B =
27-
when (this) {
28-
is Either.Right -> b
29-
is Either.Left -> control().shift(this@invoke)
30-
}
31-
}
32+
fun interface RestrictedEitherEffect<E, A> : EitherEffect<E, A>
3233

3334
@Suppress("ClassName")
3435
object either {

arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/eval.kt

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import arrow.core.Eval
55
import kotlin.coroutines.RestrictsSuspension
66

77
fun interface EvalEffect<A> : Effect<Eval<A>> {
8+
9+
@Deprecated("The monadic operator for the Arrow 1.x series will become invoke in 0.13", ReplaceWith("()"))
10+
suspend fun <B> Eval<B>.bind(): B = this()
11+
12+
@Deprecated("The monadic operator for the Arrow 1.x series will become invoke in 0.13", ReplaceWith("()"))
13+
suspend operator fun <B> Eval<B>.not(): B = this()
14+
815
suspend operator fun <B> Eval<B>.invoke(): B =
916
value()
1017
}

arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/nullable.kt

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import arrow.continuations.Effect
44
import kotlin.coroutines.RestrictsSuspension
55

66
fun interface NullableEffect<A> : Effect<A?> {
7+
8+
@Deprecated("The monadic operator for the Arrow 1.x series will become invoke in 0.13", ReplaceWith("()"))
9+
suspend fun <B> B?.bind(): B = this()
10+
11+
@Deprecated("The monadic operator for the Arrow 1.x series will become invoke in 0.13", ReplaceWith("()"))
12+
suspend operator fun <B> B?.not(): B = this()
13+
714
suspend operator fun <B> B?.invoke(): B = this ?: control().shift(null)
815
}
916

arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/computations/validated.kt

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import kotlin.coroutines.RestrictsSuspension
1010
ReplaceWith("EitherEffect", "arrow.core.computations.either.EitherEffect")
1111
)
1212
fun interface ValidatedEffect<E, A> : Effect<Validated<E, A>> {
13+
14+
@Deprecated("The monadic operator for the Arrow 1.x series will become invoke in 0.13", ReplaceWith("()"))
15+
suspend fun <B> Validated<E, B>.bind(): B = this()
16+
17+
@Deprecated("The monadic operator for the Arrow 1.x series will become invoke in 0.13", ReplaceWith("()"))
18+
suspend operator fun <B> Validated<E, B>.not(): B = this()
19+
1320
suspend operator fun <B> Validated<E, B>.invoke(): B =
1421
when (this) {
1522
is Validated.Valid -> a

0 commit comments

Comments
 (0)