Remove enumeration support from map
This commit is contained in:
parent
74fce3fc78
commit
58e4bdb1b9
@ -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()
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user