diff --git a/crates/nargo_cli/tests/execution_success/slices/src/main.nr b/crates/nargo_cli/tests/execution_success/slices/src/main.nr index cda6657b4ff..ca1c4ac2966 100644 --- a/crates/nargo_cli/tests/execution_success/slices/src/main.nr +++ b/crates/nargo_cli/tests/execution_success/slices/src/main.nr @@ -43,6 +43,11 @@ fn main(x : Field, y : pub Field) { assert(remove_slice[3] == 3); assert(remove_slice.len() == 4); + let append = [1, 2].append([3, 4, 5]); + assert(append.len() == 5); + assert(append[0] == 1); + assert(append[4] == 5); + regression_2083(); } diff --git a/noir_stdlib/src/slice.nr b/noir_stdlib/src/slice.nr index 8e344a40f5e..4f73f3a2994 100644 --- a/noir_stdlib/src/slice.nr +++ b/noir_stdlib/src/slice.nr @@ -32,5 +32,13 @@ impl [T] { /// the removed element #[builtin(slice_remove)] fn remove(_self: Self, _index: Field) -> (Self, T) { } -} + // Append each element of the `other` slice to the end of `self`. + // This returns a new slice and leaves both input slices unchanged. + fn append(mut self, other: Self) -> Self { + for elem in other { + self = self.push_back(elem); + } + self + } +}