Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .map over map #105

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions interpreter/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ pub fn map(
}
Value::List(Arc::new(values))
}
Value::Map(map) => {
let mut values = Vec::with_capacity(map.map.len());
let mut ptx = ftx.ptx.new_inner_scope();
for (key, _) in map.map.iter() {
ptx.add_variable_from_value(ident.clone(), key.clone());
let value = ptx.resolve(&expr)?;
values.push(value);
}
Value::List(Arc::new(values))
}
_ => return Err(this.error_expected_type(ValueType::List)),
}
.into()
Expand Down Expand Up @@ -613,6 +623,10 @@ mod tests {
"nested map",
"[[1, 2], [2, 3]].map(x, x.map(x, x * 2)) == [[2, 4], [4, 6]]",
),
(
"map to list",
r#"{'John': 'smart'}.map(key, key) == ['John']"#,
),
]
.iter()
.for_each(assert_script);
Expand Down