Skip to content

Commit

Permalink
feat: Add slice append (#2241)
Browse files Browse the repository at this point in the history
Add slice concat
  • Loading branch information
jfecher authored Aug 9, 2023
1 parent f74cbec commit 90c5d18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions crates/nargo_cli/tests/execution_success/slices/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
10 changes: 9 additions & 1 deletion noir_stdlib/src/slice.nr
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,13 @@ impl<T> [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
}
}

0 comments on commit 90c5d18

Please sign in to comment.