feat: add forall method to Sequence class for testing all elements pass predicate

Implement a `forall` method on the Sequence class that takes a predicate function and returns true only if every element in the sequence satisfies the predicate. The method iterates through all elements, returning false immediately upon encountering any element where the predicate does not return exactly true. Includes core library documentation and a test file verifying behavior with numeric comparisons and non-boolean predicate returns.
This commit is contained in:
Gavin Schulz
2015-01-14 07:47:01 +00:00
parent a2c7499e0a
commit 580ca8cf27
4 changed files with 27 additions and 0 deletions
+7
View File
@@ -14,6 +14,13 @@ class Sequence {
}
return result
}
forall(f) {
for (element in this) {
if (f.call(element) != true) return false
}
return true
}
}
class List is Sequence {