From 66ba25c8b69490dab7ccea9807d074a7c42a782d Mon Sep 17 00:00:00 2001 From: Artemy Date: Sun, 14 Aug 2022 23:33:38 +0300 Subject: [PATCH] feat: array method (for calculate values in arrays) --- src/interpreter.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/interpreter.rs b/src/interpreter.rs index c057260..ba69510 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -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::Array( + value + .into_iter() + .map(|val| match val { + Value::Object(_) => self.eval_node(val), + _ => val.clone(), + }) + .collect(), + ) + } + fn calc_obj(&mut self, value: &Map) -> Value { let result: Value = value .into_iter()