Fix transform loops
This commit is contained in:
parent
335fc2e454
commit
674d3c91f9
@ -33,27 +33,22 @@ impl AbstractTree for Transform {
|
||||
let expression_run = self.expression.run(source, context)?;
|
||||
let values = expression_run.as_list()?.items();
|
||||
let key = self.identifier.inner();
|
||||
let context = context.clone();
|
||||
let new_list = List::with_capacity(values.len());
|
||||
let new_list = values
|
||||
.par_iter()
|
||||
.map(|value| {
|
||||
let mut iter_context = Map::clone_from(context);
|
||||
|
||||
values.par_iter().try_for_each_with(
|
||||
(context, new_list.clone()),
|
||||
|(context, new_list), value| {
|
||||
context.set_value(key.clone(), value.clone()).unwrap();
|
||||
iter_context.set_value(key.clone(), value.clone()).unwrap();
|
||||
|
||||
let item_run = self.item.run(source, context);
|
||||
let item_run = self.item.run(source, &mut iter_context);
|
||||
|
||||
match item_run {
|
||||
Ok(value) => {
|
||||
new_list.items_mut().push(value);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Err(error) => Err(error),
|
||||
Ok(value) => value,
|
||||
Err(_) => Value::Empty,
|
||||
}
|
||||
},
|
||||
)?;
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(Value::List(new_list))
|
||||
Ok(Value::List(List::with_items(new_list)))
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,18 @@ impl Map {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clone_from(other: &Self) -> Self {
|
||||
let mut new_map = BTreeMap::new();
|
||||
|
||||
for (key, value) in other.inner().read().unwrap().iter() {
|
||||
new_map.insert(key.clone(), value.clone());
|
||||
}
|
||||
|
||||
Map {
|
||||
variables: Arc::new(RwLock::new(new_map)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a Value assigned to the identifer, allowing dot notation to retrieve Values that are /// nested in Lists or Maps. Returns None if there is no variable with a key matching the /// identifier. Returns an error if a Map or List is indexed incorrectly.
|
||||
pub fn get_value(&self, identifier: &str) -> Result<Option<Value>> {
|
||||
let variables = self.variables.read().unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user