mlld
Version:
mlld: llm scripting language
60 lines (58 loc) • 1.89 kB
JavaScript
import { isVariable } from './chunk-DUS6QZAC.mjs';
import { inheritExpressionProvenance, isStructuredValue, asData } from './chunk-RKGZ44GZ.mjs';
import { __name } from './chunk-NJQT543K.mjs';
// interpreter/eval/for-utils.ts
function attachProvenance(target, source) {
if (!target || typeof target !== "object") {
return;
}
inheritExpressionProvenance(target, source);
}
__name(attachProvenance, "attachProvenance");
function normalizeIterableValue(value) {
if (isVariable(value)) {
if (value.type === "executable") {
return value;
}
const normalized = normalizeIterableValue(value.value);
attachProvenance(normalized, value);
return normalized;
}
if (isStructuredValue(value)) {
const normalized = normalizeIterableValue(asData(value));
attachProvenance(normalized, value);
return normalized;
}
if (Array.isArray(value)) {
const normalizedArray = value.map((item) => normalizeIterableValue(item));
attachProvenance(normalizedArray, value);
return normalizedArray;
}
if (value && typeof value === "object") {
const normalizedObject = {};
for (const [key, entry] of Object.entries(value)) {
normalizedObject[key] = normalizeIterableValue(entry);
}
attachProvenance(normalizedObject, value);
return normalizedObject;
}
return value;
}
__name(normalizeIterableValue, "normalizeIterableValue");
function toIterable(value) {
const normalized = normalizeIterableValue(value);
if (Array.isArray(normalized)) {
return normalized.map((item, index) => [
String(index),
item
]);
}
if (normalized && typeof normalized === "object") {
return Object.entries(normalized);
}
return null;
}
__name(toIterable, "toIterable");
export { normalizeIterableValue, toIterable };
//# sourceMappingURL=chunk-JVJPPTN3.mjs.map
//# sourceMappingURL=chunk-JVJPPTN3.mjs.map