everyInstructionPlan

function everyInstructionPlan(instructionPlan, predicate): boolean;

Checks if every instruction plan in the tree satisfies the given predicate.

This function performs a depth-first traversal through the instruction plan tree, returning true only if the predicate returns true for every plan in the tree (including the root plan and all nested plans).

Parameters

ParameterTypeDescription
instructionPlanInstructionPlanThe instruction plan tree to check.
predicate(plan) => booleanA function that returns true if the plan satisfies the condition.

Returns

boolean

true if every plan in the tree satisfies the predicate, false otherwise.

Examples

Checking if all plans are divisible.

const plan = sequentialInstructionPlan([
  parallelInstructionPlan([instructionA, instructionB]),
  sequentialInstructionPlan([instructionC, instructionD]),
]);
 
const allDivisible = everyInstructionPlan(
  plan,
  (p) => p.kind !== 'sequential' || p.divisible,
);
// Returns true because all sequential plans are divisible.

Checking if all single instructions use a specific program.

const plan = parallelInstructionPlan([instructionA, instructionB, instructionC]);
 
const allUseSameProgram = everyInstructionPlan(
  plan,
  (p) => p.kind !== 'single' || p.instruction.programAddress === myProgramAddress,
);

See

On this page