feat: add Sequence.any method as complement to Sequence.all

Adds a new `any` method to the Sequence class that tests whether any element
in the sequence passes the given predicate function, returning true on the
first match or false if none match. Includes documentation, core library
source update, and three new test files covering basic functionality,
non-boolean return values, and non-function argument error handling.
This commit is contained in:
Thorbjørn Lindeijer
2015-02-28 20:45:39 +00:00
parent c11bb88105
commit 8f54dc5f76
6 changed files with 40 additions and 2 deletions
+10
View File
@@ -0,0 +1,10 @@
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
View File
@@ -0,0 +1 @@
IO.print([1, 2, 3].any {|x| "truthy" }) // expect: true
+1
View File
@@ -0,0 +1 @@
[1, 2, 3].any("string") // expect runtime error: String does not implement 'call(_)'.