diff options
Diffstat (limited to 'src/eval/args.rs')
| -rw-r--r-- | src/eval/args.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/eval/args.rs b/src/eval/args.rs index 67da9865..40454ff5 100644 --- a/src/eval/args.rs +++ b/src/eval/args.rs @@ -1,6 +1,6 @@ use std::fmt::{self, Debug, Formatter, Write}; -use super::{Cast, Value}; +use super::{Array, Cast, Dict, Value}; use crate::diag::{At, TypResult}; use crate::syntax::{Span, Spanned}; use crate::util::EcoString; @@ -147,6 +147,23 @@ impl Args { Ok(()) } + /// Extract the positional arguments as an array. + pub fn to_positional(&self) -> Array { + self.items + .iter() + .filter(|item| item.name.is_none()) + .map(|item| item.value.v.clone()) + .collect() + } + + /// Extract the named arguments as a dictionary. + pub fn to_named(&self) -> Dict { + self.items + .iter() + .filter_map(|item| item.name.clone().map(|name| (name, item.value.v.clone()))) + .collect() + } + /// Reinterpret these arguments as actually being an array index. pub fn into_index(self) -> TypResult<i64> { self.into_castable("index") |
