code: def apply(self, graph):
      # Copy the graph. Don't change the original.
      graph = copy.deepcopy(graph)
  
      while True:
          matches, _ = graph.search(self.pattern)
          if not matches:
              break
  
          # Replace pattern with new node
          if self.op == "__first__":
              combo = matches[0]
          elif self.op == "__last__":
              combo = matches[-1]
          else:
              combo = Node(
                  uid=graph.sequence_id(matches),
                  name=self.name
                  or " &gt; ".join([l.title for l in matches]),
                  op=self.op or self.pattern,
                  output_shape=matches[-1].output_shape,
              )
              combo._caption = "/".join(
                  filter(None, [l.caption for l in matches])
              )
          graph.replace(matches, combo)
      return graph
  
imports: import re
  import copy
  from .graph import Node
  from .None import ge
label_desc: Use image node_id 2 for calling the Fold obj's underlying member method code with example usage: obj.apply(graph) and returns: graph