I came across something that I'm not sure it's a bug or by design and if it's 
by design, whether this should be discussed here.

Example:

class Foo {
    init(number: Int) { /* ... */ }
}

let closure = Foo.init(number:) // (Int) -> Foo
[1, 2, 3].map(closure) // [Foo, Foo, Foo]

This works great until the initializer gets a default argument:

class Foo {
    init(number: Int, string: String = "") { /* ... */ }
}

// Error: Foo has no member init(number:)
let closure = Foo.init(number:) 

I was wondering if we could get closures to methods without the default 
arguments. Currently, this needs to be worked around by e.g. creating a second 
closure that invokes the method without the default arguments:

let closure: (Int) -> Foo = { Foo(number: $0) }

But to me it seems like something that should work "out of the box".

Thoughts?
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to