Skip to main content

rl_lang/interpreter/stdlib/array/
mod.rs

1//! `std::array` - array manipulation functions.
2//!
3//! All functions operate on [`Value::Values`] and return errors for non-array inputs.
4//! Higher-order functions (`map`, `filter`, `reduce`, etc.) require a [`Value::Function`]
5//! with the correct return type annotation.
6
7use super::len;
8use crate::interpreter::native::Module;
9
10mod arr_all;
11mod arr_any;
12mod arr_concat;
13mod arr_contains;
14mod arr_count;
15mod arr_fill;
16mod arr_filter;
17mod arr_find;
18mod arr_find_index;
19mod arr_first;
20mod arr_flat_map;
21mod arr_flatten;
22mod arr_for_each;
23mod arr_index_of;
24mod arr_insert;
25mod arr_is_empty;
26mod arr_last;
27mod arr_map;
28mod arr_max;
29mod arr_min;
30mod arr_pop;
31mod arr_product;
32mod arr_push;
33mod arr_range;
34mod arr_reduce;
35mod arr_remove;
36mod arr_reverse;
37mod arr_slice;
38mod arr_sort;
39mod arr_sort_by;
40mod arr_sum;
41mod arr_unique;
42mod arr_zip;
43
44pub const KEYWORDS: &[&str] = &[
45    "arr_push",
46    "arr_pop",
47    "arr_insert",
48    "arr_remove",
49    "arr_reverse",
50    "arr_concat",
51    "arr_first",
52    "arr_last",
53    "arr_max",
54    "arr_min",
55    "arr_sum",
56    "arr_product",
57    "arr_unique",
58    "arr_is_empty",
59    "arr_count",
60    "arr_contains",
61    "arr_index_of",
62    "arr_sort",
63    "arr_slice",
64    "arr_flatten",
65    "arr_range",
66    "arr_fill",
67    "arr_map",
68    "len",
69    "arr_filter",
70    "arr_all",
71    "arr_any",
72    "arr_find",
73    "arr_find_index",
74    "arr_reduce",
75    "arr_sort_by",
76    "arr_flat_map",
77    "arr_for_each",
78    "arr_zip",
79];
80
81pub fn module() -> Module {
82    Module::new("array")
83        .with_function("arr_push", arr_push::std_arr_push)
84        .with_function("arr_pop", arr_pop::std_arr_pop)
85        .with_function("arr_insert", arr_insert::std_arr_insert)
86        .with_function("arr_remove", arr_remove::std_arr_remove)
87        .with_function("arr_reverse", arr_reverse::std_arr_reverse)
88        .with_function("arr_concat", arr_concat::std_arr_concat)
89        .with_function("arr_first", arr_first::std_arr_first)
90        .with_function("arr_last", arr_last::std_arr_last)
91        .with_function("arr_max", arr_max::std_arr_max)
92        .with_function("arr_min", arr_min::std_arr_min)
93        .with_function("arr_sum", arr_sum::std_arr_sum)
94        .with_function("arr_product", arr_product::std_arr_product)
95        .with_function("arr_unique", arr_unique::std_arr_unique)
96        .with_function("arr_is_empty", arr_is_empty::std_arr_is_empty)
97        .with_function("arr_index_of", arr_index_of::std_arr_index_of)
98        .with_function("arr_count", arr_count::std_arr_count)
99        .with_function("arr_contains", arr_contains::std_arr_contains)
100        .with_function("arr_range", arr_range::std_arr_range)
101        .with_function("arr_flatten", arr_flatten::std_arr_flatten)
102        .with_function("arr_sort", arr_sort::std_arr_sort)
103        .with_function("arr_fill", arr_fill::std_arr_fill)
104        .with_function("arr_slice", arr_slice::std_arr_slice)
105        .with_function("arr_map", arr_map::std_arr_map)
106        .with_function("len", len::std_len)
107        .with_function("arr_filter", arr_filter::std_arr_filter)
108        .with_function("arr_all", arr_all::std_arr_all)
109        .with_function("arr_any", arr_any::std_arr_any)
110        .with_function("arr_find", arr_find::std_arr_find)
111        .with_function("arr_find_index", arr_find_index::std_arr_find_index)
112        .with_function("arr_reduce", arr_reduce::std_arr_reduce)
113        .with_function("arr_sort_by", arr_sort_by::std_arr_sort_by)
114        .with_function("arr_flat_map", arr_flat_map::std_arr_flat_map)
115        .with_function("arr_for_each", arr_for_each::std_arr_for_each)
116        .with_raw_function("arr_zip", arr_zip::std_arr_zip)
117}