array-mumu 0.2.0-rc.5

Array tools plugin for the Mumu ecosystem
Documentation
// src/tail.rs

use mumu::parser::types::{Value};
use mumu::parser::interpreter::Interpreter;

// The array:tail function simply returns the array excluding the first element.
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.is_empty() {
                Ok(Value::IntArray(vec![]))
            } else {
                Ok(Value::IntArray(xs[1..].to_vec()))  // Exclude the first element
            }
        }
        Value::StrArray(ss) => {
            if ss.is_empty() {
                Ok(Value::StrArray(vec![]))
            } else {
                Ok(Value::StrArray(ss[1..].to_vec()))  // Exclude the first element
            }
        }
        Value::BoolArray(bb) => {
            if bb.is_empty() {
                Ok(Value::BoolArray(vec![]))
            } else {
                Ok(Value::BoolArray(bb[1..].to_vec()))  // Exclude the first element
            }
        }
        Value::MixedArray(xs) => {
            if xs.is_empty() {
                Ok(Value::MixedArray(vec![]))
            } else {
                Ok(Value::MixedArray(xs[1..].to_vec()))  // Exclude the first element
            }
        }
        _ => Err("array:tail => argument must be an array".to_string()),  // Return error if not an array
    }
}