🏠 back to Observable

Yielding transformed output of a generator into a cell

In the Passing Signals Between Cells notebook, the Dmain cell transforms the results of the value cell; which is assigned to a ‘Generators.observe…’

What is the code pattern to have the value cell directly yield the transformation Dmain produces; eliminating the need for the Dmain cell?

Background:

The Generators.queue documentation alludes to this possibility, but it’s not clear how to implement it for the specific scenario in the notebook:

Generators.observe is typically used to define a generator cell, but you can also read the yielded values by hand.

Use Case: The cell selLambdas in this notebook is used to transform a chartFilter generator. The goal is to eliminate the need for the intermediary chartFilter cell.

Update/Solution:

The cell selLambdas in the notebook is now properly iterating through the chartFilter’s generated values.

The general pattern inferred from this discussion in the documentation would then be:

{
  const generator = Generators.observe(…);

  for (const value of generator) {

     let transformationOfValue =  
         performSomeFunctionToTransformValue(await value);    

     yield transformationOfValue;

   }
  
}
1 Like