Function: recursiveLoop()
recursiveLoop<
TInput,TOutput>(config):RecursiveLoopStep<TInput,TOutput>
Defined in: packages/core/src/pipeline/helpers.ts:271
Create a recursive loop step that processes nested structures. The body receives a recurse callback to process child elements.
Use this for tree traversal, nested comment processing, or any recursive data structure.
Type Parameters
TInput
TInput
Input type for each recursive call
TOutput
TOutput
Output type from recursive processing
Parameters
config
RecursiveLoopConfig<TInput, TOutput>
Configuration object with condition, body (receives recurse callback), and maxIterations
Returns
RecursiveLoopStep<TInput, TOutput>
RecursiveLoopStep object for use in pipelines
Example
interface Comment {
id: string;
text: string;
replies?: Comment[];
}
interface ProcessedComment {
id: string;
text: string;
sentiment: string;
replies?: ProcessedComment[];
}
const processComments = pipeline(
loadCommentThread,
recursiveLoop<Comment, ProcessedComment>({
condition: (result, depth) => result.replies && depth < 10,
body: async (comment, recurse) => {
// Process current comment
const sentiment = await analyzeSentiment(comment.text);
const processed = {
id: comment.id,
text: comment.text,
sentiment
};
// Recursively process replies
if (comment.replies) {
processed.replies = await Promise.all(
comment.replies.map(reply => recurse(reply))
);
}
return processed;
},
maxIterations: 100 // Total across all recursive calls
})
);