From cc87214750ec2e5660160e88cb905c3e951abefc Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 2 Mar 2020 17:04:45 +0800 Subject: [PATCH] Simplify code. --- src/api.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/api.rs b/src/api.rs index 6de0d2db..4b66d55d 100644 --- a/src/api.rs +++ b/src/api.rs @@ -71,15 +71,15 @@ impl Engine { ) -> Result { let AST(os, fns) = ast; - for f in fns { - let spec = FnSpec { - ident: f.name.clone(), - args: None, - }; - - self.script_fns - .insert(spec, Arc::new(FnIntExt::Int(f.clone()))); - } + fns.iter().for_each(|f| { + self.script_fns.insert( + FnSpec { + ident: f.name.clone(), + args: None, + }, + Arc::new(FnIntExt::Int(f.clone())), + ); + }); let result = os .iter() @@ -133,17 +133,18 @@ impl Engine { .map_err(|err| EvalAltResult::ErrorParsing(err)) .and_then(|AST(ref os, ref fns)| { for f in fns { + // FIX - Why are functions limited to 6 parameters? if f.params.len() > 6 { return Ok(()); } - let spec = FnSpec { - ident: f.name.clone(), - args: None, - }; - - self.script_fns - .insert(spec, Arc::new(FnIntExt::Int(f.clone()))); + self.script_fns.insert( + FnSpec { + ident: f.name.clone(), + args: None, + }, + Arc::new(FnIntExt::Int(f.clone())), + ); } let val = os