ResourceIListOps<A>
extension ResourceIListOps<A> on IList<A>Methods
flatTraverseResource() extension
Applies f to each element of this list and collects the results into a new list that is flattened using concatenation. Resources are allocated sequentially.
Available on IList<A>, provided by the ResourceIListOps<A> extension
Implementation
Resource<IList<B>> flatTraverseResource<B>(Function1<A, Resource<IList<B>>> f) =>
traverseResource(f).map((a) => a.flatten());parTraverseResource() extension
Asynchronously applies f to each element of this list and collects the results into a new list. Resources are allocated in parallel; if any allocation fails, all others are released.
Available on IList<A>, provided by the ResourceIListOps<A> extension
Implementation
Resource<IList<B>> parTraverseResource<B>(Function1<A, Resource<B>> f) {
Resource<IList<B>> result = Resource.pure(nil());
foreach((elem) {
result = Resource.both(result, f(elem)).map((t) => t((acc, b) => acc.prepended(b)));
});
return result.map((a) => a.reverse());
}parTraverseResource_() extension
Asynchronously applies f to each element of this list, discarding any results. Resources are allocated in parallel; if any allocation fails, all others are released.
Available on IList<A>, provided by the ResourceIListOps<A> extension
Implementation
Resource<Unit> parTraverseResource_<B>(Function1<A, Resource<B>> f) {
Resource<Unit> result = Resource.pure(Unit());
foreach((elem) {
result = Resource.both(result, f(elem)).map((t) => t((acc, b) => Unit()));
});
return result;
}traverseFilterResource() extension
Applies f to each element of this list and collects the results into a new list. Any results from f that are None are discarded from the resulting list. Resources are allocated sequentially.
Available on IList<A>, provided by the ResourceIListOps<A> extension
Implementation
Resource<IList<B>> traverseFilterResource<B>(Function1<A, Resource<Option<B>>> f) =>
traverseResource(f).map(
(opts) => opts.foldLeft(
IList.empty<B>(),
(acc, elem) => elem.fold(() => acc, (elem) => acc.appended(elem)),
),
);traverseResource() extension
Applies f to each element of this list and collects the results into a new list. Resources are allocated sequentially; if any allocation fails, previously allocated resources are released.
Available on IList<A>, provided by the ResourceIListOps<A> extension
Implementation
Resource<IList<B>> traverseResource<B>(Function1<A, Resource<B>> f) {
Resource<IList<B>> result = Resource.pure(nil());
foreach((elem) {
result = result.flatMap((l) => f(elem).map((b) => l.prepended(b)));
});
return result.map((a) => a.reverse());
}traverseResource_() extension
Applies f to each element of this list, discarding any results. Resources are allocated sequentially; if any allocation fails, previously allocated resources are released.
Available on IList<A>, provided by the ResourceIListOps<A> extension
Implementation
Resource<Unit> traverseResource_<B>(Function1<A, Resource<B>> f) {
var result = Resource.pure(Unit());
foreach((elem) {
result = result.flatMap((_) => f(elem).voided());
});
return result;
}