summaryrefslogtreecommitdiff
path: root/src/eval/array.rs
diff options
context:
space:
mode:
authorMarmare314 <49279081+Marmare314@users.noreply.github.com>2023-04-06 15:26:09 +0200
committerGitHub <noreply@github.com>2023-04-06 15:26:09 +0200
commit0f8219b392e96d3cf7d784ee5d474274169d9918 (patch)
tree60ce53bb076b61b09184f4f1aefa2fa63ebb3ed2 /src/eval/array.rs
parenta73149767c82509b77ccf6996ab0b1125cc9c249 (diff)
Unpacking syntax (#532)
Closes #341
Diffstat (limited to 'src/eval/array.rs')
-rw-r--r--src/eval/array.rs11
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 {