@@ -123,44 +123,13 @@ public inline fun <Error, A, B> fold(
123
123
* This method should never be wrapped in `try`/`catch` as it will not throw any unexpected errors,
124
124
* it will only result in [CancellationException], or fatal exceptions such as `OutOfMemoryError`.
125
125
*/
126
+ @OptIn(DelicateRaiseApi ::class )
126
127
@JvmName(" _fold" )
127
128
public inline fun <Error , A , B > fold (
128
129
@BuilderInference block : Raise <Error >.() -> A ,
129
130
catch : (throwable: Throwable ) -> B ,
130
131
recover : (error: Error ) -> B ,
131
132
transform : (value: A ) -> B ,
132
- ): B {
133
- contract {
134
- callsInPlace(catch , AT_MOST_ONCE )
135
- callsInPlace(recover, AT_MOST_ONCE )
136
- callsInPlace(transform, AT_MOST_ONCE )
137
- }
138
- return foldUnsafe(block, catch , recover) {
139
- if (it is Function <* > || it is Lazy <* > || it is Sequence <* >)
140
- throw IllegalStateException (
141
- """
142
- Returning a lazy computation or closure from 'fold' breaks the context scope, and may lead to leaked exceptions on later execution.
143
- Make sure all calls to 'raise' and 'bind' occur within the lifecycle of nullable { }, either { } or similar builders.
144
-
145
- See Arrow documentation on 'Typed errors' for further information.
146
- """ .trimIndent()
147
- )
148
- transform(it)
149
- }
150
- }
151
-
152
- /* *
153
- * Similar to [fold], but does *not* check for
154
- * potential lazy return types which break the
155
- * [Raise] context barrier.
156
- */
157
- @JvmName(" _foldUnsafe" )
158
- @OptIn(DelicateRaiseApi ::class )
159
- public inline fun <Error , A , B > foldUnsafe (
160
- @BuilderInference block : Raise <Error >.() -> A ,
161
- catch : (throwable: Throwable ) -> B ,
162
- recover : (error: Error ) -> B ,
163
- transform : (value: A ) -> B ,
164
133
): B {
165
134
contract {
166
135
callsInPlace(catch , AT_MOST_ONCE )
0 commit comments