mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-13 18:10:42 +01:00
Call a function on every item in a vector when given as parameter
This commit is contained in:
parent
a7d602f1ce
commit
3cb16462db
@ -323,6 +323,33 @@ pub(crate) fn eval_fn_call_expr(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some((result, _)) = prelude_func {
|
if let Some((result, _)) = prelude_func {
|
||||||
|
// If the result is nan and only one argument was given,
|
||||||
|
// it may be due to incompatible types.
|
||||||
|
if result.is_nan() && expressions.len() == 1 {
|
||||||
|
let x = eval_expr(context, &expressions[0], "")?;
|
||||||
|
|
||||||
|
// If a vector was given, call the function on every item
|
||||||
|
// in the vector.
|
||||||
|
if let KalkValue::Vector(values) = x {
|
||||||
|
let mut new_values = Vec::new();
|
||||||
|
let mut success = true;
|
||||||
|
for value in values {
|
||||||
|
if let Some(result) =
|
||||||
|
prelude::call_unary_func(context, &identifier.full_name, value, "")
|
||||||
|
{
|
||||||
|
new_values.push(result.0);
|
||||||
|
} else {
|
||||||
|
success = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if success {
|
||||||
|
return Ok(KalkValue::Vector(new_values));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user