New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-5754] Some Sequence Operations Are Missing a Lazy Implementation #48324
Comments
This, unfortunately, is not the only case where one can accidentally lose laziness. Something can probably be done to address these problems when we get conditional conformances (at the very least .lazy will be touched once the conditional conformances exist, so it makes sense to perform this work at the same time). Thanks dennisvennink (JIRA User) for pointing this out. |
Comment by Dennis Vennink (JIRA) CC: @airspeedswift, @moiseev What's the status of this bug? (Since conditional conformances have landed?) |
Should have been fixed, actually. Please verify. |
Comment by Dennis Vennink (JIRA) While Come to think of it, it's probably not implemented yet, which makes this more of a feature request. Another example: print(type(of: sequence(first: 0, next: { $0 + 1 }).lazy.prefix(10)))
// AnySequence<Int> (As an aside, the Standard Library already defines a lazily implemented |
Comment by Dennis Vennink (JIRA) Incorrectly submitted as a bug. |
What is the type you suggest the |
Comment by Dennis Vennink (JIRA) The least obtrusive and elegant solution would be a new type called (I could write an Evolution proposal, if it requires one.) |
This is opening a can of worms, unfortunately. If we take this approach, it would have to be replicated for other methods like |
/cc @airspeedswift |
I'm encountering this in relation to an UnfoldSequence, as if let i = (sequence.lazy.compactMap{$0}.first) If I say that, I lose laziness. I can work around the issue by saying if let i = (sequence.lazy.compactMap{$0}.first{_ in true}) because (I believe I'm right in adding this as a comment here, but if should be filed as an actual separate bug, please tell me and I'll do that.) |
Additional Detail from JIRA
md5: e849cf83ebd7f75ce734f35ceabb20c9
Issue Description:
prefix(_ maxLength:)
returns anAnySequence
when operating on an object that conforms toLazySequenceProtocol
making subsequent operations eager. I know we can add another call to lazy afterprefix
to get back into lazy land, but that kind of defeats the entire purpose of thelazy
property; once we're lazy we should stay lazy.Thoughts?
The text was updated successfully, but these errors were encountered: