[swift-evolution] Changing the curried static methods

Erica Sadun erica at ericasadun.com
Sun Mar 13 12:18:57 CDT 2016


> On Mar 13, 2016, at 11:09 AM, Stephen Celis via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> On Mar 13, 2016, at 9:17 AM, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> A relegated issue is that it's complicated to use curried static methods with map & foreach
>> (for example, this
>> view.subviews.forEach(UIView.removeFromSuperview)
>> doesn't work )
> 
> With a final Void return value, wouldn't that just become the following?
> 
>    view.subviews.forEach(UIView.removeFromSuperview())
> 
> I have to wonder how common this pattern is, anyway, when the following is as short and arguably easier to read:
> 
>    view.subviews.forEach { $0.removeFromSuperview() }
> 
> Does the current convention give us anything else?
> 
> It's easy enough to define a `flip` library function that converts `A -> B -> C` to `B -> A -> C`, but I do see the latter being a more powerful default than the former, even if it's unconventional.



Since removeFromSuperview doesn't take a UIView argument, it sounds like what you're looking for is
something that acts like "apply", to apply a lambda/closure/selector/whatever to each member of a collection.

view.subviews.apply(UIView.removeFromSuperview)

-- E



More information about the swift-evolution mailing list