> On 24 Jun 2016, at 17:10, Charlie Monroe via swift-evolution
> <[email protected]> wrote:
>
> If the `where` keyword were to stay in the language, how would you feel about
> extending it? One major argument is that it is not as powerful as guard or
> if. How about something like this was allowed:
>
> for text in self.texts where let data = text.data(usingEncoding:
> NSASCIIEncoding) {
> /// Do something with data or text
> }
>
I noticed this in some code I was writing just now and came to mention it.
Right now I’ve got this (Note: tagsForGroup is [String?]):
> for (index, range) in zip(groupRanges.indices, groupRanges) where
> tagsForGroup[index] != nil {
>
> let tagForGroup = tagsForGroup[index]!
> // tag `range` with `tagForGroup`
> }
It would be nicer to write it like this:
> for (index, range) in zip(groupRanges.indices, groupRanges) where let tag =
> tagsForGroup[index] {
>
> // tag `range` with `tag`
> }
I could do it with a guard, but as somebody so eloquently put, it produces more
divergent constructs for readers. It’s part of a complex regex matching and
processing workflow, so I want to keep it readable and make it explicit that
we’re only tagging/processing groups where a tag is defined.
Karl
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution