class_docstr: ForEach context manager.
  
  ForEach context manager is a declarative version of For loop in a pipeline
  defintion (in DSL). When some TFX components generate more than one artifacts,
  or resolver function returns a multiple inputs, ForEach is used to handle
  each artifact or input dictionary individually.
  
  ```python
  example_gen = BufferedExampleGen()
  # example_gen.outputs['examples'] containing N artifacts.
  
  with ForEach(example_gen.outputs['examples']) as examples:
    trainer = Trainer(
        examples=examples,  # instead of using example_gen.outputs['examples'].
        ...)
  ```
  
  In the above example, only a single Trainer component is declared in the
  pipeline, but it can be executed multiple times (or even zero time) in a
  single pipeline run depending on the number of output artifacts that
  example_gen has generated.
  
  ResolverFunction can also output a loopable which can be accessed from the
  handle as a dict of channels:
  
  ```python
  evaluator_inputs = sliding_window(examples=examples)
  
  with ForEach(evaluator_inputs) as each_input:
    evaluator = Evaluator(
        examples=each_input['examples'],
        model=trainer.outputs['model'],
        ...
    )
  ```
class_docstr_tok: ["ForEach","context","manager",".","ForEach","context","manager","is","a","declarative","version","of","For","loop","in","a","pipeline","defintion","(","in","DSL",")",".","When","some","TFX","components","generate","more","than","one","artifacts",",","or","resolver","function","returns","a","multiple","inputs",",","ForEach","is","used","to","handle","each","artifact","or","input","dictionary","individually",".","``","`","python","example_gen","=","BufferedExampleGen","(",")","#","example_gen.outputs","[","'examples","'","]","containing","N","artifacts",".","with","ForEach","(","example_gen.outputs","[","'examples","'","]",")","as","examples",":","trainer","=","Trainer","(","examples=examples",",","#","instead","of","using","example_gen.outputs","[","'examples","'","]",".","...",")","``","`","In","the","above","example",",","only","a","single","Trainer","component","is","declared","in","the","pipeline",",","but","it","can","be","executed","multiple","times","(","or","even","zero","time",")","in","a","single","pipeline","run","depending","on","the","number","of","output","artifacts","that","example_gen","has","generated",".","ResolverFunction","can","also","output","a","loopable","which","can","be","accessed","from","the","handle","as","a","dict","of","channels",":","``","`","python","evaluator_inputs","=","sliding_window","(","examples=examples",")","with","ForEach","(","evaluator_inputs",")","as","each_input",":","evaluator","=","Evaluator","(","examples=each_input","[","'examples","'","]",",","model=trainer.outputs","[","'model","'","]",",","...",")","``","`"]
code: def create_context(self) -> ForEachContext:
      return for_each_internal.ForEachContext()
  
file_path: tfx/tfx/dsl/control_flow/for_each.py
imports: from typing import Union, cast, Any
  from tfx.dsl.context_managers import dsl_context_manager
  from tfx.dsl.control_flow import for_each_internal
  from tfx.dsl.input_resolution import resolver_function
  from tfx.dsl.input_resolution.ops import ops
  from tfx.types import channel
label_desc: Use image node_id 2 for calling the ForEach obj's underlying member method code with example usage: obj.create_context() and returns: for_each_internal