delete method

ZipperLocation<ZR, ZI, ZS> delete()

Remove the current node from the zipper We first try to move to the right then to the left, and otherwise up

Implementation

ZipperLocation<ZR, ZI, ZS> delete() {
  if (path is TopPath) {
    throw Exception("delete of top");
  }
  final p = path as NodePath<ZS, ZR>;

  if (p.right.isNotEmpty) {
    return update(
      node: p.right.first,
      path: NodePath(
        left: p.left,
        parentPath: p.parentPath,
        parentNode: p.parentNode,
        right: List.unmodifiable(p.right.skip(1)),
      ),
    );
  } else if (p.left.isNotEmpty) {
    return update(
      node: p.left.first,
      path: NodePath(
        left: List.unmodifiable(p.left.skip(1)),
        parentPath: p.parentPath,
        parentNode: p.parentNode,
        right: p.right,
      ),
    );
  } else {
    return update(
      node: makeSection(p.parentNode, List.unmodifiable([])),
      path: p.parentPath,
    );
  }
}