[swift-evolution] Proposal: Add SequenceType.first

Kevin Ballard kevin at sb.org
Thu Dec 31 15:33:36 CST 2015


On Thu, Dec 31, 2015, at 12:40 AM, Dave Abrahams wrote:
>> Another motivation for adding this that I forgot to mention is that
>> today the code `someCol.lazy.filter(pred).first` actually isn't lazy
>> at all, it filters the entire collection and builds a new array
>> (because SequenceType doesn't have .first so it resolves the
>> .filter() to the eager version instead of the lazy version).
>
> Oh, that’s nasty.  I wonder if there’s something we can do with
> ambiguity to make the eager overload inaccessible in that context?
> Would you mind opening a bug for this?

Incidentally, I misspoke; the problem is with
`someSeq.lazy.filter(pred).first`. `LazyCollection.filter` returns a
`CollectionType`, so `someCol.lazy.filter(pred).first` works fine there.

-Kevin Ballard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151231/6e41b086/attachment.html>


More information about the swift-evolution mailing list