Swift.LazySequence should have a .first property
| Originator: | brent | ||
| Number: | rdar://20627241 | Date Originated: | 20-Apr-2015 06:01 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.3 (6D570) |
| Classification: | UI/Usability | Reproducible: | Always |
Summary:
LazySequence should have a `first` property of type `S.Generator.Element?`.
Steps to Reproduce:
1. Try to find the first element matching a given criterion:
return lazy(start…end).filter { $0 % 2 == 0 }.first
Expected Results:
This code, or something very similar, works fine.
Actual Results:
There is no first property, method, or function that can be used on a LazySequence. The closest equivalent is to use its generator directly, capturing it in a mutable variable first:
var gen = lazy(start…end).filter { $0 % 2 == 0 }.generate()
return gen.next()
Notes:
Another alternative would be to add a first() function that takes a SequenceType, but this would be uglier and also would consume elements from one-time-through sequences, which might be unexpected.
Calling `first` twice on a LazySequence might run the `filter` method’s block twice. That would be fine.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!