mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Add isEmpty to Sequence.
Thanks, Michel and Thorbjørn!
This commit is contained in:
@ -52,6 +52,8 @@ class Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
isEmpty { iterate(null) ? false : true }
|
||||
|
||||
map(transformation) { new MapSequence(this, transformation) }
|
||||
|
||||
where(predicate) { new WhereSequence(this, predicate) }
|
||||
|
||||
@ -61,6 +61,13 @@ Iterates over the sequence, passing each element to the given `function`.
|
||||
:::dart
|
||||
["one", "two", "three"].each {|word| IO.print(word) }
|
||||
|
||||
### **isEmpty**
|
||||
|
||||
Returns whether the sequence contains any elements.
|
||||
|
||||
This can be more efficient that `count == 0` because this does not iterate over
|
||||
the entire sequence.
|
||||
|
||||
### **join**(sep)
|
||||
|
||||
Returns a string representation of the sequence. The string representations of
|
||||
|
||||
@ -66,6 +66,8 @@ static const char* coreLibSource =
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" isEmpty { iterate(null) ? false : true }\n"
|
||||
"\n"
|
||||
" map(transformation) { new MapSequence(this, transformation) }\n"
|
||||
"\n"
|
||||
" where(predicate) { new WhereSequence(this, predicate) }\n"
|
||||
|
||||
10
test/core/sequence/is_empty.wren
Normal file
10
test/core/sequence/is_empty.wren
Normal file
@ -0,0 +1,10 @@
|
||||
IO.print([].isEmpty) // expect: true
|
||||
IO.print([1].isEmpty) // expect: false
|
||||
|
||||
class InfiniteSequence is Sequence {
|
||||
iterate(iterator) { true }
|
||||
iteratorValue(iterator) { iterator }
|
||||
}
|
||||
|
||||
// Should not try to iterate the whole sequence.
|
||||
IO.print((new InfiniteSequence).isEmpty) // expect: false
|
||||
Reference in New Issue
Block a user