[Review] SE-0045: Add scan, prefix(while:), drop(while:), and iterate to the stdlib

I really don't want to see this discussion die as I have a vested interest in getting this functionality into
Swift 3. So let me suggest that

`sequence(_:, next:) -> AdHocSequence`

might be a Swift acceptable solution. We're not going to see fold/unfold pair happen. It's a given that
`reduce` is a fixed point in Swift space and `sequence` well describes what this should be doing.

So is it possible to push forward with `sequence`, whose only negative seems to be that it's not as well
loved as `unfold`?

-- Erica

···

On May 1, 2016, at 5:13 AM, Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org> wrote:

The proposal has been updated as per feedback from the core team (https://github.com/apple/swift-evolution/pull/275\). This includes removing some last vestiges of Swift 2 naming as well as replacing `iterate(_:apply:)` with an overloaded function `unfold(_:applying:)`.

The proposal says this:

  public func unfold<T, State>(_ initialState: State, applying: State -> (T, State)?) -> UnfoldSequence<T>
  public func unfold<T>(_ initialElement: T, apply: T -> T) -> UnfoldSequence<T>

However, the comment implies that the second one should instead be this:

  public func unfold<T>(_ initialElement: T, applying: T -> T?) -> UnfoldSequence<T>

I'm not sure I like having these be overloaded on only the return type of the closure. Maybe we could do something like this?

  public func unfold<T, State>(fromState initialState: State, applying: State -> (T, State)?) -> UnfoldSequence<T>
  public func unfold<T>(fromFirst initialElement: T, apply: T -> T) -> UnfoldSequence<T>

That way you're calling either `unfold(fromState:applying:)` or `unfold(fromFirst:applying:)`. (Some further bikeshedding might be needed here—it's late and I'm tired.)