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
+14 -2
View File
@@ -11,13 +11,25 @@ core [iterator protocol][] can extend this to get a number of helpful methods.
Tests whether all the elements in the sequence pass the `predicate`.
Iterates over the sequence, passing each element to the function `predicate`.
If it returns `false`, stops iterating and returns `false`. Otherwise, returns
`true`.
If its return value evaluates to `false`, stops iterating and returns `false`.
Otherwise, returns `true`.
:::dart
[1, 2, 3].all {|n| n > 2} // False.
[1, 2, 3].all {|n| n < 4} // True.
### **any**(predicate)
Tests whether any element in the sequence passes the `predicate`.
Iterates over the sequence, passing each element to the function `predicate`.
If its return value evaluates to `true`, stops iterating and returns `true`.
Otherwise, returns `false`.
:::dart
[1, 2, 3].any {|n| n < 1} // False.
[1, 2, 3].any {|n| n > 2} // True.
### **join**(sep)
Returns a string representation of the list. The string representations of the