feat: array method

(for calculate values in arrays)
This commit is contained in:
Artemy 2022-08-14 23:33:38 +03:00
parent f1259a6b1b
commit 66ba25c8b6

View file

@ -183,6 +183,14 @@ impl Interpreter {
self.error("Unsupported data type for the `scope` argument, must be an array");
}
},
"arr" => match value {
Value::Array(value) => {
return self.calc_arr(value);
}
_ => {
self.error("Unsupported data type for the `arr` argument, must be an array");
}
},
"obj" => match value {
Value::Object(value) => {
return self.calc_obj(value);
@ -223,6 +231,18 @@ impl Interpreter {
return Value::Null;
}
fn calc_arr(&mut self, value: &Vec<Value>) -> Value {
Value::Array(
value
.into_iter()
.map(|val| match val {
Value::Object(_) => self.eval_node(val),
_ => val.clone(),
})
.collect(),
)
}
fn calc_obj(&mut self, value: &Map<String, Value>) -> Value {
let result: Value = value
.into_iter()