Is this operator common in other languages? I would actually expect that the conversation is not 'almost-implicit' but completely implicit instead. I think both - a prefix and postfix operator - are not obvious enough what happens here, especially because this kind of conversion is not happening in other parts of the language. All conversions are implicit (from explicit type to protocol, from Swift stdlib types to Objective-C types, from any type to Any, …) currently.
______________________ Benjamin Herzog > On 8. Jul 2017, at 22:10, Hooman Mehr via swift-evolution > <[email protected]> wrote: > > I like this promote operator idea. I have been defining similar operators for > specific projects almost at random. It makes sense to come up with a > well-defined behavior and name for such operators, as a common practice as > you suggest. > > The problem with the postfix operator is that it does not currently work > without an extra set of parenthesis: > > postfix operator ^ > > postfix func ^<T,U>(lhs: KeyPath<T,U>) -> (T)->U { return { $0[keyPath: lhs] > } } > > struct Guy { let name: String } > > let guys = [ > Guy(name: "Benjamin"), > Guy(name: "Dave"), > Guy(name: "Brent"), > Guy(name: "Max") > ] > > guys.map(\.name^) // Error: Invalid component of Swift key path > > guys.map((\.name)^) // This works > > Is this a bug? > > That is the reason I used a prefix operator (~) in my suggestion in the a > previous e-mail on this thread.
signature.asc
Description: Message signed with OpenPGP
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
