@@ -139,6 +139,11 @@ inline fun <T, R> Resource<T>.map(crossinline transform: (data: T) -> R): Resour
139
139
return Resource (value)
140
140
}
141
141
142
+ /* * All resources completed, whether they're in success or failure state. */
143
+ fun <T > Iterable<Resource<T>>.allTerminal (): Boolean {
144
+ return this .all { it.isTerminal }
145
+ }
146
+
142
147
/* * All resources succeeded. */
143
148
fun <T > Iterable<Resource<T>>.allSuccesful (): Boolean {
144
149
return this .all { it.isSuccess }
@@ -157,6 +162,11 @@ fun <T> Iterable<Resource<T>>.anyLoading(): Boolean {
157
162
/* * Any resource empty */
158
163
fun <T > Iterable<Resource<T>>.anyEmpty (): Boolean = this .any { it.isEmpty }
159
164
165
+ fun <T > Iterable<Resource<T>>.onAllTerminal (fn : () -> Unit ): Iterable <Resource <T >> {
166
+ if (this .allTerminal()) fn()
167
+ return this
168
+ }
169
+
160
170
fun <T > Iterable<Resource<T>>.onAllSuccessful (fn : () -> Unit ): Iterable <Resource <T >> {
161
171
if (this .allSuccesful()) fn()
162
172
return this
@@ -177,4 +187,8 @@ fun <T> Iterable<Resource<T>>.onAnyEmpty(fn: () -> Unit): Iterable<Resource<T>>
177
187
return this
178
188
}
179
189
180
- fun Iterable<Task>.onAnyIdle (fn : () -> Unit ): Iterable <Task > = onAnyEmpty(fn).map { it as Task }
190
+ fun Iterable<Task>.onAnyIdle (fn : () -> Unit ): Iterable <Task > = onAnyEmpty(fn).map { it as Task }
191
+
192
+ /* * Returns the first exception that can be found in a list of resources, null if it can't find any */
193
+ fun <T > Iterable<Resource<T>>.firstExceptionOrNull () : Throwable ? =
194
+ this .firstOrNull { it.isFailure && it.exceptionOrNull() != null }?.exceptionOrNull()
0 commit comments