diff options
| author | Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> | 2023-04-25 11:22:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-25 11:22:20 +0200 |
| commit | f38989358e768ebe17c5f191cf9026d513e6f6b7 (patch) | |
| tree | 1cc6f1637a824ab6471e7ca9550d44b4266d6cf4 /src/eval/array.rs | |
| parent | d5d98b67a83944d72a5c0f8e8e2f43aeee667122 (diff) | |
Add a zip method to arrays (#947)
Diffstat (limited to 'src/eval/array.rs')
| -rw-r--r-- | src/eval/array.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/eval/array.rs b/src/eval/array.rs index 1166ce94..f6e2f2d4 100644 --- a/src/eval/array.rs +++ b/src/eval/array.rs @@ -306,6 +306,18 @@ impl Array { Ok(result) } + /// Zips the array with another array. If the two arrays are of unequal length, it will only + /// zip up until the last element of the smaller array and the remaining elements will be + /// ignored. The return value is an array where each element is yet another array of size 2. + pub fn zip(&self, other: Array) -> Array { + self.iter() + .zip(other) + .map(|(first, second)| { + Value::Array(Array::from_vec(eco_vec![first.clone(), second])) + }) + .collect() + } + /// Return a sorted version of this array, optionally by a given key function. /// /// Returns an error if two values could not be compared or if the key function (if given) |
