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
-9
View File
@@ -1,9 +0,0 @@
var a = [1, 2, 3]
var b = a.all {|x| x > 1 }
IO.print(b) // expect: false
var d = a.all {|x| x > 0 }
IO.print(d) // expect: true
var e = [].all {|x| false }
IO.print(e) // expect: true
@@ -1 +0,0 @@
IO.print([1, 2, 3].all {|x| "truthy" }) // expect: true
-1
View File
@@ -1 +0,0 @@
[1, 2, 3].all("string") // expect runtime error: String does not implement 'call(_)'.
-10
View File
@@ -1,10 +0,0 @@
var a = [1, 2, 3]
var b = a.any {|x| x > 3 }
IO.print(b) // expect: false
var d = a.any {|x| x > 1 }
IO.print(d) // expect: true
var e = [].any {|x| true }
IO.print(e) // expect: false
@@ -1 +0,0 @@
IO.print([1, 2, 3].any {|x| "truthy" }) // expect: true
-1
View File
@@ -1 +0,0 @@
[1, 2, 3].any("string") // expect runtime error: String does not implement 'call(_)'.