mirror of
https://github.com/typst/typst
synced 2025-05-22 04:55:29 +08:00
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.
|
/// Transform each item in the array with a function.
|
||||||
pub fn map(&self, vm: &mut Vm, func: Func) -> SourceResult<Self> {
|
pub fn map(&self, vm: &mut Vm, func: Func) -> SourceResult<Self> {
|
||||||
let enumerate = func.argc() == Some(2);
|
|
||||||
self.iter()
|
self.iter()
|
||||||
.enumerate()
|
.map(|item| {
|
||||||
.map(|(i, item)| {
|
let args = Args::new(func.span(), [item.clone()]);
|
||||||
let mut args = Args::new(func.span(), []);
|
|
||||||
if enumerate {
|
|
||||||
args.push(func.span(), Value::Int(i as i64));
|
|
||||||
}
|
|
||||||
args.push(func.span(), item.clone());
|
|
||||||
func.call_vm(vm, args)
|
func.call_vm(vm, args)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -73,17 +73,6 @@ impl Func {
|
|||||||
self
|
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.
|
/// Call the function with the given arguments.
|
||||||
pub fn call_vm(&self, vm: &mut Vm, mut args: Args) -> SourceResult<Value> {
|
pub fn call_vm(&self, vm: &mut Vm, mut args: Args) -> SourceResult<Value> {
|
||||||
match &self.repr {
|
match &self.repr {
|
||||||
@ -346,15 +335,6 @@ impl Closure {
|
|||||||
|
|
||||||
result
|
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 {
|
impl From<Closure> for Func {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user