rangefromList static method

A1Range rangefromList(
  1. List<A1Partial?> listFrom,
  2. List<A1Partial?> listTo, {
  3. Object? tag,
  4. A1? anchor,
})

Conveniance function for determining range from a list of partials

Implementation

static A1Range rangefromList(
    List<A1Partial?> listFrom, List<A1Partial?> listTo,
    {Object? tag, A1? anchor}) {
  const maxInt = -1 >>> 1;

  // clean the nulls and create from list
  final fromItems = listFrom.where((element) => element != null);
  final fromColumns =
      fromItems.map((A1Partial? e) => e?.column ?? 0).toList();
  fromColumns.sort();
  final fromColumn = fromColumns.first;
  final fromRows = fromItems.map((A1Partial? e) => e?.row ?? 0).toList();
  fromRows.sort();
  final fromRow = fromRows.first;

  // clean the nulls and create to list
  final toItems = listTo.where((element) => element != null);
  final toColumns =
      toItems.map((A1Partial? e) => e?.column ?? maxInt).toList();
  toColumns.sort();

  final toColumn = toColumns.last;
  final toRows = toItems.map((A1Partial? e) => e?.row ?? maxInt).toList();
  toRows.sort();
  final toRow = toRows.last;

  return A1Range.fromPartials(
    A1Partial.fromVector(fromColumn, fromRow),
    A1Partial.fromVector(
        toColumn == maxInt ? null : toColumn, toRow == maxInt ? null : toRow),
    tag: tag,
    anchor: anchor,
  );
}