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:
Bob Nystrom
2015-03-28 10:18:45 -07:00
parent a7fafce265
commit 07f9d4d2be
11 changed files with 64 additions and 65 deletions
+20 -20
View File
@@ -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"