mirror of
https://github.com/artegoser/ONLang
synced 2024-12-22 17:13:46 +03:00
feat: array method
(for calculate values in arrays)
This commit is contained in:
parent
f1259a6b1b
commit
66ba25c8b6
1 changed files with 20 additions and 0 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue