From 785087aa43cf962855724b8fa5da393022204a14 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 29 Sep 2022 13:12:19 +0200 Subject: Add $find(, ), $find_index(, ) functions The $find() function returns true if the sequence contains the specified value. The $find_index() function returns the index of the first element in the sequence that is equal to the specified value or $size() if none is found. For string sequences, it's possible to request case- insensitive comparison with a flag. --- tests/function/builtin/testscript | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/function/builtin') diff --git a/tests/function/builtin/testscript b/tests/function/builtin/testscript index bbfd4e5..3c430d7 100644 --- a/tests/function/builtin/testscript +++ b/tests/function/builtin/testscript @@ -100,6 +100,20 @@ $* <'print $sort([uint64s] 0 2 1 000, dedup)' >'0 1 2' : dedup } +: find +: +{ + $* <'print $find([uint64s] 1 2 3, 2)' >'true' : basics-true + $* <'print $find([uint64s] 1 2 3, 0)' >'false' : basics-false +} + +: find_index +: +{ + $* <'print $find_index([int64s] -1 -2 -3, -2)' >'1' : basics-true + $* <'print $find_index([int64s] -1 -2 -3, 0)' >'3' : basics-false +} + : getenv : { -- cgit v1.1