Tweak Sequence.all() and Sequence.any().
When possible, they return the actual value from the predicate instead of always just "true" and "false". This matches && and || which evaluate to the RHS or LHS when appropriate.
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