diff options
Diffstat (limited to 'src/eval/array.rs')
| -rw-r--r-- | src/eval/array.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/eval/array.rs b/src/eval/array.rs index 8dcbd5a9..394191ea 100644 --- a/src/eval/array.rs +++ b/src/eval/array.rs @@ -322,6 +322,17 @@ impl Array { usize::try_from(if index >= 0 { index } else { self.len().checked_add(index)? }) .ok() } + + /// Enumerate all items in the array. + pub fn enumerate(&self) -> Self { + let v = self + .iter() + .enumerate() + .map(|(i, value)| array![i, value.clone()]) + .map(Value::Array) + .collect(); + Self::from_vec(v) + } } impl Debug for Array { |
