[swift-evolution] [Idea] custom infix functions

Adrian Zubarev adrian.zubarev at devandartist.com
Fri Apr 22 14:13:22 CDT 2016


I must correct myself, I’m a bit sleepy.

infix func with<T: AnyObject>(lhs: T, rhs: @noescape (T) -> Void) -> T {

    rhs(lhs)
    return lhs
}

This one will do the trick.
-- 
Adrian Zubarev

Am 22. April 2016 bei 21:07:00, Adrian Zubarev (adrian.zubarev at devandartist.com) schrieb:

I’d like to throw an idea in the room and see where this will go.

What if Swift would allow us to create custom infix functions?
Does Swift need to ability of infix functions? 
How powerful can such a feature be?
Pros and cons?

There is a discussion about the `with` statement which we could develop with infix functions like so:

infix func with<T: AnyObject>(lhs: T, rhs: @noescape (T) -> Void) {

rhs(lhs)
}

class A {

func foo() {}
}

let instance: A = A() with { 

$0.foo()
}

So what does the Swift community think about that idea?

-- 
Adrian Zubarev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160422/91956832/attachment.html>


More information about the swift-evolution mailing list