microcad_lang/eval/
tuple.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4use crate::eval::*;
5
6impl Eval for TupleExpression {
7    fn eval(&self, context: &mut EvalContext) -> EvalResult<Value> {
8        let (unnamed, named): (Vec<_>, _) = Eval::<ArgumentValueList>::eval(&self.args, context)?
9            .iter()
10            .map(|(id, arg)| (id.clone(), arg.value.clone()))
11            .partition(|(id, _)| id.is_none());
12
13        Ok(Value::Tuple(
14            Tuple {
15                named: named.into_iter().collect(),
16                unnamed: unnamed.into_iter().map(|(_, v)| (v.ty(), v)).collect(),
17                src_ref: self.src_ref.clone(),
18            }
19            .into(),
20        ))
21    }
22}