I wanted to take the community's temperature on a feature that I find myself reaching for relatively often and always have to remind myself why it doesn't work. The minimal example is code such as the following:
struct Foo {
var x: Int
}
func foo(from x: Int?) -> Foo? {
return x.map(.init(x:))
}
which fails because the type of the argument to map is (Int) throws -> Foo (not Foo), which doesn't have any init(x:) member. The fix today is relatively simple, but forces us to abandon either point-free syntax or implicit member syntax:
return x.map { .init(x: $0) }
or
return x.map(Foo.init(x:))
I think it would be feasible to introduce an additional rule for implicit member syntax of the form:
If the contextual type is a function type (T1, ..., Tn) -> U, then we will look for members in type U.
What do people think? Would this be useful, or too magical?