diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 01:39:19 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 01:39:19 -0400 |
| commit | 23209a0aab983501701c62ac87c891309a7d3d58 (patch) | |
| tree | 33121163daed16729ee25f8ca6e6f2df57b04249 /builtins/array.c | |
| parent | 7126755275f12e6278031e78ff33f65801b133dd (diff) | |
Use optional ints in the array find()/first() API
Diffstat (limited to 'builtins/array.c')
| -rw-r--r-- | builtins/array.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/builtins/array.c b/builtins/array.c index a6786e0f..c9064eed 100644 --- a/builtins/array.c +++ b/builtins/array.c @@ -13,6 +13,7 @@ #include "array.h" #include "functions.h" #include "integers.h" +#include "optionals.h" #include "table.h" #include "text.h" #include "types.h" @@ -227,20 +228,19 @@ public Int_t Array$find(Array_t arr, void *item, const TypeInfo *type) if (generic_equal(item, arr.data + i*arr.stride, item_type)) return I(i+1); } - return I(0); + return NULL_INT; } -public void *Array$first(Array_t arr, closure_t predicate) +public Int_t Array$first(Array_t arr, closure_t predicate) { bool (*is_good)(void*, void*) = (void*)predicate.fn; for (int64_t i = 0; i < arr.length; i++) { if (is_good(arr.data + i*arr.stride, predicate.userdata)) - return arr.data + i*arr.stride; + return I(i+1); } - return NULL; + return NULL_INT; } - public void Array$sort(Array_t *arr, closure_t comparison, int64_t padded_item_size) { if (arr->data_refcount != 0 || (int64_t)arr->stride != padded_item_size) |
