use crate::eval::coercion::to_bool;
use crate::eval::functions::check_arity;
use crate::types::Value;
pub fn not_fn(args: &[Value]) -> Value {
if let Some(err) = check_arity(args, 1, 1) {
return err;
}
not_scalar_or_array(&args[0])
}
fn not_scalar_or_array(v: &Value) -> Value {
match v {
Value::Array(items) => {
let mapped: Vec<Value> = items.iter().map(not_scalar_or_array).collect();
Value::Array(mapped)
}
Value::Text(s) if s.is_empty() => Value::Bool(true),
_ => match to_bool(v.clone()) {
Ok(b) => Value::Bool(!b),
Err(e) => e,
},
}
}
#[cfg(test)]
mod tests;