feat: changes

This commit is contained in:
2026-01-30 17:04:36 +01:00
parent 43efe3a91d
commit 8c61468710
8 changed files with 113 additions and 50 deletions

View File

@@ -152,25 +152,35 @@ export function mapParseResult(
};
}
export function iterActions(
export function iterActions<T = void>(
chord: ChordMeta,
callback: (action: ActionMeta) => void,
) {
callback: (action: ActionMeta) => T | void,
): T | undefined {
if (chord.input) {
for (const action of chord.input.actions) {
callback(action);
const result = callback(action);
if (result !== undefined) {
return result;
}
}
}
if (chord.compounds) {
for (const compound of chord.compounds) {
for (const action of compound.actions) {
callback(action);
const result = callback(action);
if (result !== undefined) {
return result;
}
}
}
}
if (chord.phrase) {
for (const action of chord.phrase.actions) {
callback(action);
const result = callback(action);
if (result !== undefined) {
return result;
}
}
}
return undefined;
}