[swift-evolution] Fixing the confusion between non-mutating algorithms and single-pass sequences

Anton Zhilin antonyzhilin at gmail.com
Wed Jul 13 10:43:50 CDT 2016


I also thought on the problem, and I agree with your solution. It keeps
things simple.
I agree with this specific name -- IterableOnce (not IterableAtLeastOnce).
IterableOnce contains Iterable -- and that plays very nicely with
IteratorProtocol name.
IterableOnce is not a single word, but it's not too long, compared to some
other options.
Functions working with IterableOnce will always imply single-pass, and with
Collections -- multi-pass. It might seem odd that Collection conforms to
IterableOnce, but I consider that a minor drawback.

2016-07-13 1:55 GMT+03:00 Dmitri Gribenko via swift-evolution <
swift-evolution at swift.org>:

> Hi,
>
> I'd like to continue the discussion of the issue raised by David Waite
> inhttp://thread.gmane.org/gmane.comp.lang.swift.evolution/21295/:
>
> > My main motivation for proposing this is the potential for developer
> confusion. As stated during one of the previous threads on the naming of
> map, flatMap, filter, etc. methods on Sequence, Sequence has a naming
> requirement not typical of the rest of the Swift standard library in that
> many methods on Sequence may or may not be destructive. As such, naming
> methods for any extensions on Sequence is challenging as the names need to
> not imply immutability.
>
> I'd like to focus on a particular point: methods on Sequence can
> consume elements, but the APIs are not markedmutating.
>
> Dave Abrahams, Max Moiseev, and I have discussed this issue and we
> agree this problem is severe and worth solving, we also think that the
> likely solutions would be source-breaking, so it is important that we
> discuss it now.
>
> We have discussed a few options.
>
> - Rejected option: remove Sequence, let IteratorProtocol model
> single-pass data streams
>
> - Rejected option: use a syntactic marker, like sequence.consumedIn.map {}
>
> - Rejected option: mutating APIs on Sequence, non-mutating APIs on
> Collection
>
> Proposed: rename Sequence to IterableOnce or TraversableOnce. We think
> that Sequence does not convey the single-pass restriction clearly. The
> term "sequence" has been used in math (as in "integer sequence"), and
> since the math domain does not have mutation, "sequence" can be
> understood to mean "multi-pass", since you can traverse a sequence of
> integers an arbitrary number of times.
>
> We think that only the last option is viable in the Swift language as
> it exists now, without creating an undue burden for API vendors and
> users.
>
> For more details about rejection options, please see the full writeup:
> https://gist.github.com/gribozavr/47f4717f3afc762549383e94da7f748b
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160713/7c02f86a/attachment.html>


More information about the swift-evolution mailing list