From 0f8219b392e96d3cf7d784ee5d474274169d9918 Mon Sep 17 00:00:00 2001 From: Marmare314 <49279081+Marmare314@users.noreply.github.com> Date: Thu, 6 Apr 2023 15:26:09 +0200 Subject: Unpacking syntax (#532) Closes #341 --- src/eval/array.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/eval/array.rs') 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 { -- cgit v1.2.3