@@ -139,6 +139,11 @@ inline fun <T, R> Resource<T>.map(crossinline transform: (data: T) -> R): Resour
139139 return Resource (value)
140140}
141141
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+
142147/* * All resources succeeded. */
143148fun <T > Iterable<Resource<T>>.allSuccesful (): Boolean {
144149 return this .all { it.isSuccess }
@@ -157,6 +162,11 @@ fun <T> Iterable<Resource<T>>.anyLoading(): Boolean {
157162/* * Any resource empty */
158163fun <T > Iterable<Resource<T>>.anyEmpty (): Boolean = this .any { it.isEmpty }
159164
165+ fun <T > Iterable<Resource<T>>.onAllTerminal (fn : () -> Unit ): Iterable <Resource <T >> {
166+ if (this .allTerminal()) fn()
167+ return this
168+ }
169+
160170fun <T > Iterable<Resource<T>>.onAllSuccessful (fn : () -> Unit ): Iterable <Resource <T >> {
161171 if (this .allSuccesful()) fn()
162172 return this
@@ -177,4 +187,8 @@ fun <T> Iterable<Resource<T>>.onAnyEmpty(fn: () -> Unit): Iterable<Resource<T>>
177187 return this
178188}
179189
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