Retoor software development Projects Research SearchXNG
Register Sign In

10 lines
201 B
Plaintext
Raw Normal View History

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.
2015-01-14 08:47:01 +01:00
var a = [1, 2, 3]
var b = a.forall {|x| x > 1 }
IO.print(b) // expect: false
var c = a.forall {|x| x.toString }
IO.print(c) // expect: false
var d = a.forall {|x| x > 0 }
IO.print(d) // expect: true
Reference in New Issue Copy Permalink
580ca8cf27
wren/test/list/forall.wren
Response time: 27ms
Mail Licenses API