I&#39;ll duly oblige with some pushback on `suchThat`. I get that you&#39;re trying to clarify whether filter retains or gets rid of elements that match the predicate, but I don&#39;t think &quot;filter such that&quot; expresses this idea at all.<br><br>Comparing to &quot;filter where,&quot; &quot;filter such that&quot; is equally susceptible to misinterpretation that you are filtering to remove elements that are matched. For example: &quot;find me some apples, filtering such that are bruised.&quot;<br><br>I&#39;d suggest that if you want to be perfectly clear, you&#39;d need something like `filter(keepingWhere:)`.<br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 22, 2016 at 18:33 Dave Abrahams via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
on Tue Jun 21 2016, Dave Abrahams &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
<br>
&gt; on Mon Jun 20 2016, Brent Royal-Gordon &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt;&gt; A couple of weeks ago we started to notice that we had some poorly-named<br>
&gt;&gt;&gt; closure parameters and argument labels in the standard library, so we<br>
&gt;&gt;&gt; did a complete audit of the standard library&#39;s APIs and came up with a<br>
&gt;&gt;&gt; preliminary proposal for changes, which we applied in a branch and you<br>
&gt;&gt;&gt; can review in <a href="https://github.com/apple/swift/pull/2981" rel="noreferrer" target="_blank">https://github.com/apple/swift/pull/2981</a>.  Let&#39;s please<br>
&gt;&gt;&gt; carry on further discussion here rather than in the pull request, though.<br>
&gt;&gt;<br>
&gt;&gt; In general, I like this; `orderingBy` is a particularly nice<br>
&gt;&gt; improvement over the old `isOrderedBefore` convention.<br>
&gt;<br>
&gt; I don&#39;t really love the use of “by”, FWIW, but I thought `orderingWith`<br>
&gt; was more confusable (ordering A with B might swap A and B, whereas the<br>
&gt; parameter is a closure).  It could be argued, though, that I am being<br>
&gt; overly concerned with unlikely misinterpretations, at the cost of<br>
&gt; “naturalness”—a known weakness of mine ;-).  Anyway, as ever I&#39;m open to<br>
&gt; discussion on this.<br>
&gt;<br>
&gt;&gt; A few specific comments about things I don&#39;t like:<br>
&gt;&gt;<br>
&gt;&gt; * In `map` and `flatMap`, I&#39;m not sure how much `transform` buys us<br>
&gt;&gt;   over `elementTransform`.<br>
&gt;<br>
&gt; I think you mean the converse.  And I agree that `elementTransform`<br>
&gt; is probably not an improvement over `transform`.<br>
<br>
...and I&#39;ve gone back to `transform` in my PR.<br>
<br>
&gt;&gt; * In general, I&#39;m not a fan of most of the changes away from `where`<br>
&gt;&gt; labels.<br>
&gt;<br>
&gt; The only such changes I can find are in<br>
&gt; <a href="https://github.com/apple/swift/pull/2981/commits/3418eede88d724ad23731fe8f412f51e03cf5106" rel="noreferrer" target="_blank">https://github.com/apple/swift/pull/2981/commits/3418eede88d724ad23731fe8f412f51e03cf5106</a><br>
&gt;<br>
&gt; Note that part of this change was to make all filter closures<br>
&gt; consistent; in the main `filter` API there was no label at all.<br>
&gt; However, we felt that there&#39;s a real clarity problem with the polarity<br>
&gt; of the argument (we talk about “filtering things out” but the closure<br>
&gt; indicates which elements to keep).  And we couldn&#39;t find a “where”-based<br>
&gt; name that began to clarify it.<br>
&gt;<br>
&gt; I will argue that even changing to “suchThat,” as in the PR, does not<br>
&gt; sufficiently clarify the closure&#39;s polarity, and the only true fix for<br>
&gt; filter is to use a different base name (some have suggested “select,”<br>
&gt; and I have other ideas), but that is out of scope for this particular<br>
&gt; set of changes.  So if the community is happier with a “where” label<br>
&gt; here I can live with it.  I do think “suchThat” is marginally clearer.<br>
<br>
I have not received any further pushback on “suchThat,” so I&#39;ve left it<br>
alone.<br>
<br>
&gt;<br>
&gt;&gt; Those are a nice, straightforward convention applied broadly across<br>
&gt;&gt; the Sequence APIs. (Yes, I criticized `where` as a method name in<br>
&gt;&gt; another thread, but I don&#39;t think `where` is a problem when there&#39;s a<br>
&gt;&gt; function base name to give it context.) When they don&#39;t work, that&#39;s<br>
&gt;&gt; usually because of a less-than-ideal base name. I&#39;m not saying that<br>
&gt;&gt; *all* base names that aren&#39;t compatible with `where` should be<br>
&gt;&gt; changed, but rather that if `where` is not enough, that&#39;s an API<br>
&gt;&gt; smell.<br>
&gt;&gt;<br>
&gt;&gt; * In particular, `elementWhere` is not a good label for the same<br>
&gt;&gt; reason that `removeElement` is not a good name. Session 403 last week<br>
&gt;&gt; actually talked about this between roughly minutes 8 and 11. (I&#39;m sure<br>
&gt;&gt; you know about its content; you probably saw it before we did.)<br>
&gt;<br>
&gt; Yes I do, and I think you misinterpreted the message in that session.<br>
&gt; There&#39;s nothing wrong with repeating type information when it&#39;s<br>
&gt; necessary for clarity or fluency at the use-site.  In the case of<br>
&gt; `contains(elementWhere:)`, it&#39;s there for fluency:<br>
&gt;<br>
&gt;        customers.contains(where: isSingle)<br>
&gt;<br>
&gt; doesn&#39;t read as well as:<br>
&gt;<br>
&gt;        customers.contains(elementWhere: isSingle)<br>
&gt;<br>
&gt; The point is not to imagine that every argument should be preceded by<br>
&gt; a noun, and repetition of type information is often the result of<br>
&gt; trying to do that.<br>
&gt;<br>
&gt;&gt; * I like `separatedWhere` on `split`, but I think the Equatable<br>
&gt;&gt; version needs a similar renaming.<br>
&gt;<br>
&gt; That&#39;s a nice thought; I think it&#39;s arguably out-of-scope here, though.<br>
&gt;<br>
&gt;&gt; Perhaps `separatedBy`?  `separatedOn`? The usual opposite of `where`,<br>
&gt;&gt; `of`, doesn&#39;t work here. (Alternatively, `separatedWhere` could be<br>
&gt;&gt; `separatorWhere` instead, but that&#39;s not quite as elegant.)<br>
&gt;<br>
&gt; I&#39;d want to consider variations of `separatingAt` or `onSeparator` or<br>
&gt; `atSeparator` too... which makes me thing “separatedWhere” might not be<br>
&gt; as good as “separatingWhere” for the closure version.<br>
&gt;<br>
&gt;&gt; * I&#39;m very uncomfortable with the amount of weight<br>
&gt;&gt; `accumulatingResultBy` adds to `reduce`. `combinedBy` seems perfectly<br>
&gt;&gt; cromulent to me. I&#39;m even more concerned by your suggestion in the<br>
&gt;&gt; pull request body of<br>
&gt;&gt; `accumulating(startingFrom:combiningBy:)`. `reduce` is a subtle and<br>
&gt;&gt; slightly confusing operation; adding more words to its call sites will<br>
&gt;&gt; not solve that problem. If you want to invent a new name from whole<br>
&gt;&gt; cloth, I would probably use something like `combining(with<br>
&gt;&gt; initialResult: T, by nextResult: (T, Element) -&gt; T)`. (For that<br>
&gt;&gt; matter, while we&#39;re working in this area, `sequence(first:next:)`<br>
&gt;&gt; could use a similar coat of paint.)<br>
&gt;<br>
&gt; As with `filter(suchThat:`, `reduce(accumulatingResultBy:` is attempting<br>
&gt; to solve with an argument label what IMO is a grave weakness in clarity<br>
&gt; of the base name.  If you read the documentation for `reduce`, you&#39;ll<br>
&gt; see that it&#39;s all about accumulating a result, and if you consider that<br>
&gt; its current signature often leads to O(N^2) behavior and we are thinking<br>
&gt; about adding an overload that takes its “accumulator” inout, the<br>
&gt; arguments for avoiding the name “accumulate” get progressively weaker.<br>
&gt; But as noted earlier, changing base names is out-of-scope for this<br>
&gt; proposal.  As with “filter,” I could live with leaving this alone,<br>
&gt; though I do believe “accumulatingResultBy:” is a real improvement in<br>
&gt; clarity.<br>
<br>
...but I think it&#39;s overly specific at the expense of smoothness.  So<br>
I&#39;ve removed `Result` from that name.<br>
<br>
&gt;&gt; * I agree with the comment on GitHub that `invoke` should be<br>
&gt;&gt; `execute`.<br>
&gt;<br>
&gt; Why?  Rationales help.<br>
&gt;<br>
&gt;&gt; If you see a distinction between the two cases on the number of<br>
&gt;&gt; arguments, I would then suggest `passTo` as the label on these<br>
&gt;&gt; methods: `views.forEach(passTo: addSubview)`,<br>
&gt;&gt; `withUnsafeBufferPointer(&amp;bytes, passTo: Data.init(buffer:))`.<br>
&gt;<br>
&gt; Those are intriguing ideas, but that direction tends to suggest this<br>
&gt; would be better:<br>
&gt;<br>
&gt;   views.passEach(to: addSubview)<br>
&gt;   passUnsafeBufferPointer(to: Data.init(buffer:))<br>
&gt;<br>
&gt; ...until you pass a trailing closure:<br>
&gt;<br>
&gt;   views.passEach { addSubView($0) }<br>
&gt;   passUnsafeBufferPointer { Data.init(buffer:$0) }<br>
&gt;<br>
&gt; (note: withUnsafeBufferPointer takes only one argument, a closure).<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; * It&#39;s a little odd that you&#39;re using `comparingBy` for `Equatable`<br>
&gt;&gt; and `orderingBy` for `Comparable`. Did you judge `equatingBy` to be<br>
&gt;&gt; too awkward?<br>
&gt;<br>
&gt; Yes, and because it&#39;s not “equating,” which would mean using equality<br>
&gt; (==) it&#39;s “testing equivalence” with respect to the predicate.<br>
&gt;<br>
&gt;&gt; Perhaps the real problem is that `Equatable` ought to be `Comparable`<br>
&gt;&gt; and `Comparable` ought to be `Orderable`?<br>
&gt;<br>
&gt; I don&#39;t think so, personally, but regardless I consider such a change<br>
&gt; out-of-scope for this proposal.<br>
&gt;<br>
&gt;&gt; Or maybe `comparingBy` should just be something more general, like<br>
&gt;&gt; `matchingBy`? That would make perfectly sensible but slightly odd use<br>
&gt;&gt; cases like this one read better:<br>
&gt;&gt;<br>
&gt;&gt;      let isAnIdiot = luggageCombination.starts(with: [1, 2, 3, 4,<br>
&gt;&gt; 5], matchingBy: &lt;=) // Matches [1,2,3,4,5], but also [1,1,1,1,1],<br>
&gt;&gt; [1,2,3,2,1], etc.<br>
&gt;<br>
&gt; That would not be legal, as &lt;= is not an equivalence relation.  You<br>
&gt; could think about redefining the meaning of `starts(with:` to not<br>
&gt; require an equivalence relation, but that&#39;s something I&#39;m not confident<br>
&gt; *I* know how to do meaningfully, and regardless is again out-of-scope.<br>
&gt;<br>
&gt;&gt; Very soon (hopefully), I will be posting an early draft of a proposal<br>
&gt;&gt; renaming the various first/last/prefix/suffix/etc. APIs. I believe the<br>
&gt;&gt; only place it touches on your proposal is in<br>
&gt;&gt; `starts(with:isEquivalent:)`, but I think your changes to the second<br>
&gt;&gt; parameter label can be easily incorporated into what I&#39;m doing.<br>
&gt;<br>
&gt; Great!<br>
<br>
I&#39;m going to write up the proposal ASAP based on the current PR unless I<br>
get more feedback.<br>
<br>
Thanks,<br>
<br>
--<br>
Dave<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>