Skip to content

IOIListOps<A>

extension IOIListOps<A> on IList<A>

Methods

flatTraverseIO() extension

IO<IList<B>> flatTraverseIO<B>(IO<IList<B>> Function(A) f)

Applies f to each element of this list and collects the results into a new list that is flattened using concatenation. If an error or cancelation is encountered for any element, that result is returned and any additional elements will not be evaluated.

Available on IList<A>, provided by the IOIListOps<A> extension

Implementation
dart
IO<IList<B>> flatTraverseIO<B>(Function1<A, IO<IList<B>>> f) =>
    traverseIO(f).map((a) => a.flatten());

parTraverseIO() extension

IO<IList<B>> parTraverseIO<B>(IO<B> Function(A) f)

Asynchronously applies f to each element of this list and collects the results into a new list. If an error or cancelation is encountered for any element, that result is returned and all other elements will be canceled if possible.

Available on IList<A>, provided by the IOIListOps<A> extension

Implementation
dart
IO<IList<B>> parTraverseIO<B>(Function1<A, IO<B>> f) {
  IO<IList<B>> result = IO.pure(nil());

  foreach((elem) {
    result = IO.both(result, f(elem)).map((t) => t((acc, b) => acc.prepended(b)));
  });

  return result.map((a) => a.reverse());
}

parTraverseIO_() extension

IO<Unit> parTraverseIO_<B>(IO<B> Function(A) f)

Asynchronously applies f to each element of this list, discarding any results. If an error or cancelation is encountered for any element, that result is returned and all other elements will be canceled if possible.

Available on IList<A>, provided by the IOIListOps<A> extension

Implementation
dart
IO<Unit> parTraverseIO_<B>(Function1<A, IO<B>> f) {
  IO<Unit> result = IO.pure(Unit());

  foreach((elem) {
    result = IO.both(result, f(elem)).map((t) => t((acc, b) => Unit()));
  });

  return result;
}

traverseFilterIO() extension

IO<IList<B>> traverseFilterIO<B>(IO<Option<B>> Function(A) f)

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. If an error or cancelation is encountered for any element, that result is returned and any additional elements will not be evaluated.

Available on IList<A>, provided by the IOIListOps<A> extension

Implementation
dart
IO<IList<B>> traverseFilterIO<B>(Function1<A, IO<Option<B>>> f) => traverseIO(f).map(
  (opts) => opts.foldLeft(
    IList.empty<B>(),
    (acc, elem) => elem.fold(() => acc, (elem) => acc.appended(elem)),
  ),
);

traverseIO() extension

IO<IList<B>> traverseIO<B>(IO<B> Function(A) f)

Applies f to each element of this list and collects the results into a new list. If an error or cancelation is encountered for any element, that result is returned and any additional elements will not be evaluated.

Available on IList<A>, provided by the IOIListOps<A> extension

Implementation
dart
IO<IList<B>> traverseIO<B>(Function1<A, IO<B>> f) {
  IO<IList<B>> result = IO.pure(nil());

  foreach((elem) {
    result = result.flatMap((l) => f(elem).map((b) => l.prepended(b)));
  });

  return result.map((a) => a.reverse());
}

traverseIO_() extension

IO<Unit> traverseIO_<B>(IO<B> Function(A) f)

Applies f to each element of this list, discarding any results. If an error or cancelation is encountered for any element, that result is returned and any additional elements will not be evaluated.

Available on IList<A>, provided by the IOIListOps<A> extension

Implementation
dart
IO<Unit> traverseIO_<B>(Function1<A, IO<B>> f) {
  var result = IO.pure(Unit());

  foreach((elem) {
    result = result.flatMap((l) => f(elem).map((b) => Unit()));
  });

  return result;
}