toAsync<R> method

Future<List<R>> toAsync<R>(
  1. Future<R> combine(
    1. int index,
    2. E element
    ), {
  2. bool reverse = false,
  3. int limit = 0,
})

Implementation

Future<List<R>> toAsync<R>(
  Future<R> Function(int index, E element) combine, {
  bool reverse = false,
  int limit = 0,
}) async {
  List<R> initial = [];
  if (isEmpty) return initial;
  int index = reverse ? length - 1 : 0;
  while (index >= 0 && index < length && elementAtOrNull(index) != null) {
    if (initial.length >= limit) break;
    initial.add(await combine(index, elementAt(index)));
    index = reverse ? index - 1 : index + 1;
  }
  return initial;
}