[swift-evolution] [Pitch] Enumerate from offset
Xiaodi Wu
xiaodi.wu at gmail.com
Wed May 10 08:43:25 CDT 2017
Without rehashing the previous thread, the primary motivation is that it's
very harmful as it encourages pervasively incorrect use. Namely, people
often mistaken the offset for the index. A quick look through major
open-source Swift projects shows that the offset is almost exclusively used
for subscripting. It happens to work for arrays, but it is not correct for
collections generally, not even for array slices.
On Wed, May 10, 2017 at 08:30 BJ Homer <bjhomer at gmail.com> wrote:
> I don't see the motivation for removing enumerated(). It's a
> source-breaking change that seems unjustified to me. Sure, enumerated()
> isn't as flexible as one might like, and you can certainly reproduce its
> effects with zip(), but I don't think we've demonstrated that enumerated()
> is actively harmful. Removing it means obsolescing a bunch of training
> material, blog posts, etc. What do we gain by removing it?
>
>
> -BJ
>
> On May 10, 2017, at 7:24 AM, Xiaodi Wu via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> When this was previously brought up, I believe the consensus was for
> removing enumerated and doing nothing else.
> On Wed, May 10, 2017 at 02:50 Pavol Vaskovic <pali at pali.sk> wrote:
>
>> One more note:
>>
>> On Sun, May 7, 2017 at 8:51 PM, Ben Cohen <ben_cohen at apple.com> wrote:
>>
>>>
>>> let words = ["five","four","three","two","one","blastoff!"]
>>> ((0...5).reversed() |> { zip($0, words) })
>>> .forEach { print($0.0,$0.1, separator: ": ") }
>>>
>>> ...
>>>
>>
>>> ((0...5).reversed() |> zip(_, words))
>>> .forEach { print($0.0,$0.1, separator: ": ") }
>>>
>>
>> The code above demonstrates that replacing `enumerated` with `zip` gives
>> you anonymous tuples that need to be accessed with positional properties.
>>
>> In contrast, the tuple returned from `enumerated` gives you named tuple
>> (offset: Int, element: Element).
>>
>> Does this change your opinion when you take into account the sorry state
>> of tuple handling in Swift 4, that prevents you from writing concise and
>> readable functional code? See:
>>
>> SR-4745 for (index, (a, b)) in dict.enumerated() produces an error
>> https://bugs.swift.org/browse/SR-4745
>>
>> SR-4738 Can not decompose nested tuple in closure arguments
>> https://bugs.swift.org/browse/SR-4738
>>
>> Best regards
>> Pavol Vaskovic
>>
> _______________________________________________
>
>
> 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/20170510/06d7bd15/attachment.html>
More information about the swift-evolution
mailing list