[Pitch]Add a Lazy split function for Sequence

Hi, Swift Community.

I use the Swift programming language, and initially believed that the split function is eager. However, it turns out that it does not.

As shown below, the lazy map is designed.

// a huge collection
let giant = 0..<Int.max
// lazily map it: no work is done yet
let mapped = giant.lazy.map { $0 * 2 }
// sum the first few elements
let sum = mapped.prefix(10).reduce(0, +)
// sum == 90

So, How about this?

// a long sequence
let lazySplited = "".lazy.split(separator: ".")

I found inspiration from the following URL.

I always welcome your thoughts, questions, and, feedback.

Thank you for reading!

Hi! Here’s one example of an earlier discussion that may interest you:

There are other discussions on the topic that you can also find using the search function on this site.

1 Like