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:
Bob Nystrom
2015-03-28 17:18:45 +00:00
parent adc64d65b9
commit 540a4a166a
11 changed files with 64 additions and 65 deletions
+10
View File
@@ -0,0 +1,10 @@
var a = [1, 2, 3]
IO.print(a.any {|x| x > 3 }) // expect: false
IO.print(a.any {|x| x > 1 }) // expect: true
IO.print([].any {|x| true }) // expect: false
// Returns first truthy value.
IO.print(a.any {|x| x }) // expect: 1
// Returns last falsey value.
IO.print(a.any {|x| x < 2 ? null : false }) // expect: false