Add reverse function to arrays.

This commit is contained in:
Stephen Chung 2020-09-24 10:51:21 +08:00
parent d91d983c74
commit 9fcbda1ba4
2 changed files with 5 additions and 0 deletions

View File

@ -41,6 +41,7 @@ The following methods (mostly defined in the [`BasicArrayPackage`][packages] but
| `pop` | _none_ | removes the last element and returns it ([`()`] if empty) | | `pop` | _none_ | removes the last element and returns it ([`()`] if empty) |
| `shift` | _none_ | removes the first element and returns it ([`()`] if empty) | | `shift` | _none_ | removes the first element and returns it ([`()`] if empty) |
| `remove` | index | removes an element at a particular index and returns it, or returns [`()`] if the index is not valid | | `remove` | index | removes an element at a particular index and returns it, or returns [`()`] if the index is not valid |
| `reverse` | _none_ | reverses the array |
| `len` method and property | _none_ | returns the number of elements | | `len` method and property | _none_ | returns the number of elements |
| `pad` | element to pad, target length | pads the array with an element to at least a specified length | | `pad` | element to pad, target length | pads the array with an element to at least a specified length |
| `clear` | _none_ | empties the array | | `clear` | _none_ | empties the array |

View File

@ -133,6 +133,10 @@ mod array_functions {
list.clear(); list.clear();
} }
} }
#[inline(always)]
pub fn reverse(list: &mut Array) {
list.reverse();
}
} }
fn pad<T: Variant + Clone>( fn pad<T: Variant + Clone>(