goRight method

ZipperLocation<ZR, ZI, ZS> goRight()

Move to the sibling on the right

Implementation

ZipperLocation<ZR, ZI, ZS> goRight() {
  if (path is TopPath) {
    throw Exception("right of top");
  }
  NodePath<ZS, ZR> p = path as NodePath<ZS, ZR>;
  if (p.right.isEmpty) {
    throw Exception("right of last");
  }
  ZR l = p.right.first;
  final newLeft = List<ZR>.unmodifiable([node, ...p.left]);
  final newRight = List<ZR>.unmodifiable(p.right.skip(1));
  return update(
    node: l,
    path: NodePath(
      left: newLeft,
      right: newRight,
      parentPath: p.parentPath,
      parentNode: p.parentNode,
    ),
  );
}