Renaming Trailing-closure Functions in the Standard Library

The harm here is indeed that there's two ways to call it: one with the label and one without. Renaming first(where:) to firstWhere(_:) does solves the problem, but in a way that goes against the naming guidelines. It also forces every call site to be updated, regardless of whether using the trailing closure syntax of not.

I'd rather see a way to make the label mandatory, perhaps like this:

func first(@explicit where: (Element) -> Bool)

One effect this could have is to forbid calls using the trailing closure syntax. We could also add the ability to add a label in the trailing closure syntax in a similar way to labels in the amended SE-0279 currently being reviewed. A warning + a fixit would nudge you in the right direction.

Half the time I'm using first(where:), it is within an if condition where I can't use the trailing closure syntax anyway. Changing the name means I have to rename it everywhere, whereas disallowing unlabelled calls only requires changes to where the trailing closure syntax is actually used.

Note: I'm suggesting @explicit here because it seems most backward compatible. Personally I think it'd fit better in the language to have explicit be the default and @implicit for when the label is allowed to be omitted.

1 Like