Replace

Overview

In-place node replacement for tree-shaped data during TreeRewrite transforms.

Locates a node under a root container and swaps it for a new value without rebuilding the entire tree.

Qwiratry::Mold.make calls this service when a transformer composes TreeRewrite. Replacement is identity-based: the old node must be the exact object currently present under the root, not merely an equal value. That keeps rewrites predictable when multiple nodes have the same contents.

The service supports the container shapes used by the built-in tree walker: positional children, associative children, and direct associative values. If the root itself is being replaced, compatible containers are mutated in place so external references to the root remain valid.

Methods

instance()

method instance(--> Qwiratry::Tree::Replace)

Returns the shared replacement service instance.

replace-node(Mu $old, Mu $new, Mu $root)

method replace-node(Mu $old, Mu $new, Mu $root --> Bool)

Parameters

  • $old

The existing node or value to find in the tree.
  • $new

The replacement value to install in place of the old node.
  • $root

The traversal root that provides the data context for the plan.

Replaces $old with $new under $root.

Returns true when a replacement occurred. Undefined inputs and nodes that cannot be found return false; callers can use that to decide whether a TreeRewrite mold actually mutated the input structure.

!replace-in-parent(Mu $parent, Mu $old, Mu $new)

method !replace-in-parent(Mu $parent, Mu $old, Mu $new --> Bool)

Parameters

  • $parent

The parent container inspected while searching for the node to replace.
  • $old

The existing node or value to find in the tree.
  • $new

The replacement value to install in place of the old node.

Replaces $old within a discovered parent container.

The method handles positional slots, associative children arrays, and direct hash values. It returns false when the parent has no supported slot for the old node.

!merge-into-container(Mu $container, Mu $new)

method !merge-into-container(Mu $container, Mu $new --> Bool)

Parameters

  • $container

The mutable container that should receive the replacement contents.
  • $new

The replacement value to install in place of the old node.

Merges a replacement into the root container when the root itself matched.

Hash roots receive the new hash keys and values; positional roots are spliced to contain the new list. Other shape changes return false because they cannot preserve the original root object identity.

Qwiratry v0.10.0

Declarative query and data-walking architecture for Raku, with transformers, molds, walkers, and I/O pipelines.

Authors

  • Tim Nelson

License

Dependencies

SlangifyImplementation::Loader:ver<0.0.9+>Glob::Grammar

Test Dependencies

Provides

  • Qwiratry
  • Qwiratry::Context
  • Qwiratry::Format
  • Qwiratry::Format::Base
  • Qwiratry::Format::CSVdemo
  • Qwiratry::Format::JSONdemo
  • Qwiratry::Format::NDJSONdemo
  • Qwiratry::Location
  • Qwiratry::Location::Base
  • Qwiratry::Location::File
  • Qwiratry::Mold
  • Qwiratry::Mold::Compiler
  • Qwiratry::Mold::Registry
  • Qwiratry::Mold::Slang
  • Qwiratry::Operator::Capability
  • Qwiratry::Operator::IO
  • Qwiratry::Operator::MapReduce
  • Qwiratry::Operator::Navigation
  • Qwiratry::Operator::Set
  • Qwiratry::Query::Evaluator::Eager
  • Qwiratry::Query::Evaluator::Filter
  • Qwiratry::Query::Evaluator::Join
  • Qwiratry::Query::Evaluator::Lazy
  • Qwiratry::Query::Evaluator::MapReduce
  • Qwiratry::Query::Evaluator::Navigation
  • Qwiratry::Query::Evaluator::Relational
  • Qwiratry::Query::Evaluator::Row
  • Qwiratry::Query::Evaluator::Set
  • Qwiratry::Query::Evaluator::Union
  • Qwiratry::Query::Extract
  • Qwiratry::Query::NamedJoins
  • Qwiratry::Query::RelationCommon
  • Qwiratry::Query::Runtime
  • Qwiratry::Query::Selector
  • Qwiratry::Query::Slang
  • Qwiratry::Query::Slang::Ops
  • Qwiratry::Query::Slang::Topic
  • Qwiratry::Query::Specificity
  • Qwiratry::Query::Topic
  • Qwiratry::QueryCursor
  • Qwiratry::QueryIterator
  • Qwiratry::QueryMatch
  • Qwiratry::Setup
  • Qwiratry::Strategy
  • Qwiratry::Strategy::ControlSignal
  • Qwiratry::Strategy::FinishResult
  • Qwiratry::Strategy::RewriteSpec
  • Qwiratry::Strategy::Traversal
  • Qwiratry::Suggest
  • Qwiratry::Table
  • Qwiratry::Table::Schema
  • Qwiratry::Transformer
  • Qwiratry::Transformer::Copy
  • Qwiratry::Transformer::TreeRewrite
  • Qwiratry::Tree::Navigator
  • Qwiratry::Tree::Navigator::Base
  • Qwiratry::Tree::Navigator::Filesystem
  • Qwiratry::Tree::Navigator::Match
  • Qwiratry::Tree::Navigator::RakuAST
  • Qwiratry::Tree::Replace
  • Qwiratry::Walker
  • Qwiratry::Walker::Capabilities
  • Qwiratry::Walker::Factory
  • Qwiratry::Walker::Implementation::Table
  • Qwiratry::Walker::Implementation::Tree
  • Qwiratry::Walker::Master
  • Qwiratry::Walker::Providing
  • TypedIterator
  • WalkCursor
  • X::Qwiratry

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.