diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-04-11 16:41:04 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-04-11 16:41:04 +0200 |
| commit | 58e4bdb1b95a7c7f048f38e231328054e753b898 (patch) | |
| tree | 556b0db7815ded355702ada72271743ed1ad8f8d | |
| parent | 74fce3fc78604e1d13517f88b8f07dcd738cf865 (diff) | |
Remove enumeration support from `map`
| -rw-r--r-- | src/eval/array.rs | 10 | ||||
| -rw-r--r-- | src/eval/func.rs | 20 |
2 files changed, 2 insertions, 28 deletions
diff --git a/src/eval/array.rs b/src/eval/array.rs index 6bd2eb47..b04fdab8 100644 --- a/src/eval/array.rs +++ b/src/eval/array.rs @@ -181,15 +181,9 @@ impl Array { /// Transform each item in the array with a function. pub fn map(&self, vm: &mut Vm, func: Func) -> SourceResult<Self> { - let enumerate = func.argc() == Some(2); self.iter() - .enumerate() - .map(|(i, item)| { - let mut args = Args::new(func.span(), []); - if enumerate { - args.push(func.span(), Value::Int(i as i64)); - } - args.push(func.span(), item.clone()); + .map(|item| { + let args = Args::new(func.span(), [item.clone()]); func.call_vm(vm, args) }) .collect() diff --git a/src/eval/func.rs b/src/eval/func.rs index 93da6d7b..d64ca732 100644 --- a/src/eval/func.rs +++ b/src/eval/func.rs @@ -73,17 +73,6 @@ impl Func { self } - /// The number of positional arguments this function takes, if known. - pub fn argc(&self) -> Option<usize> { - match &self.repr { - Repr::Closure(closure) => closure.argc(), - Repr::With(arc) => Some(arc.0.argc()?.saturating_sub( - arc.1.items.iter().filter(|arg| arg.name.is_none()).count(), - )), - _ => None, - } - } - /// Call the function with the given arguments. pub fn call_vm(&self, vm: &mut Vm, mut args: Args) -> SourceResult<Value> { match &self.repr { @@ -346,15 +335,6 @@ impl Closure { result } - - /// The number of positional arguments this closure takes, if known. - fn argc(&self) -> Option<usize> { - if self.sink.is_some() { - return None; - } - - Some(self.params.iter().filter(|(_, default)| default.is_none()).count()) - } } impl From<Closure> for Func { |
