feat: make Sequence.all() and Sequence.any() return actual predicate values instead of booleans
Rewrite all() and any() to store and return the predicate's result directly, matching && and || semantics. Update documentation to describe the new behavior. Move tests from test/core/list/ to test/core/sequence/ and add cases verifying that the first falsey/truthy value is returned.
This commit is contained in:
+20
-20
@@ -45,11 +45,27 @@
|
||||
// This string literal is generated automatically from core. Do not edit.
|
||||
static const char* libSource =
|
||||
"class Sequence {\n"
|
||||
" all(f) {\n"
|
||||
" var result = true\n"
|
||||
" for (element in this) {\n"
|
||||
" result = f.call(element)\n"
|
||||
" if (!result) return result\n"
|
||||
" }\n"
|
||||
" return result\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" any(f) {\n"
|
||||
" var result = false\n"
|
||||
" for (element in this) {\n"
|
||||
" result = f.call(element)\n"
|
||||
" if (result) return result\n"
|
||||
" }\n"
|
||||
" return result\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" contains(element) {\n"
|
||||
" for (item in this) {\n"
|
||||
" if (element == item) {\n"
|
||||
" return true\n"
|
||||
" }\n"
|
||||
" if (element == item) return true\n"
|
||||
" }\n"
|
||||
" return false\n"
|
||||
" }\n"
|
||||
@@ -65,9 +81,7 @@ static const char* libSource =
|
||||
" count(f) {\n"
|
||||
" var result = 0\n"
|
||||
" for (element in this) {\n"
|
||||
" if (f.call(element)) {\n"
|
||||
" result = result + 1\n"
|
||||
" }\n"
|
||||
" if (f.call(element)) result = result + 1\n"
|
||||
" }\n"
|
||||
" return result\n"
|
||||
" }\n"
|
||||
@@ -88,20 +102,6 @@ static const char* libSource =
|
||||
" return result\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" all(f) {\n"
|
||||
" for (element in this) {\n"
|
||||
" if (!f.call(element)) return false\n"
|
||||
" }\n"
|
||||
" return true\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" any(f) {\n"
|
||||
" for (element in this) {\n"
|
||||
" if (f.call(element)) return true\n"
|
||||
" }\n"
|
||||
" return false\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" reduce(acc, f) {\n"
|
||||
" for (element in this) {\n"
|
||||
" acc = f.call(acc, element)\n"
|
||||
|
||||
Reference in New Issue
Block a user