mumu-array 0.1.2

Array tools plugin for the MuMu/Lava language
Documentation
use mumu::{
    parser::types::Value,
    Interpreter,
};

/// `array:tail` bridging function — returns a copy of the array without the first element.
/// This version does NOT support partial usage, so we require exactly 1 argument:
///   array:tail([1,2,3]) => [2,3]
///
/// If the array has length 0 or 1, we return an empty array. 
/// If it's not an IntArray, StrArray, or BoolArray, we raise an error. 
/// We do NOT handle KeyedArray for tail, just as Ramda doesn't handle 'tail' on objects.
pub fn array_tail_bridge(
    _interp: &mut Interpreter,
    args: Vec<Value>
) -> Result<Value, String> {
    if args.len() != 1 {
        return Err("array:tail => expected exactly 1 argument".to_string());
    }

    let arr_val = &args[0];
    match arr_val {
        Value::IntArray(xs) => {
            if xs.len() <= 1 {
                Ok(Value::IntArray(vec![]))
            } else {
                Ok(Value::IntArray(xs[1..].to_vec()))
            }
        }
        Value::StrArray(ss) => {
            if ss.len() <= 1 {
                Ok(Value::StrArray(vec![]))
            } else {
                Ok(Value::StrArray(ss[1..].to_vec()))
            }
        }
        Value::BoolArray(bb) => {
            if bb.len() <= 1 {
                Ok(Value::BoolArray(vec![]))
            } else {
                Ok(Value::BoolArray(bb[1..].to_vec()))
            }
        }
        other => {
            Err(format!("array:tail => argument must be an IntArray, StrArray, or BoolArray, got {:?}", other))
        }
    }
}