mapPos<R> method Null safety

Iterable<R> mapPos<R>(
  1. R mapper(
    1. T item,
    2. IterationPosition pos
    )
)

Implementation

Iterable<R> mapPos<R>(R mapper(T item, IterationPosition pos)) {
  int i = 0;
  final length = this.length;
  final isSingle = length == 1;
  return [
    ...this.map((T item) {
      final _i = i;
      i++;
      return mapper(
          item,
          isSingle
              ? IterationPosition.only
              : _i == 0
                  ? IterationPosition.first
                  : _i == length - 1
                      ? IterationPosition.last
                      : IterationPosition.middle);
    })
  ];
}