Re: [swift-users] Quick Question about ExpressibleByStringLiteral

2017-03-09 Thread David Sweeris via swift-users
Great! Thanks, Andrew :-)

- Dave Sweeris

> On Mar 9, 2017, at 6:00 PM, Jordan Rose  wrote:
> 
> Andrew Bennett is two steps ahead of you. :-) 
> https://github.com/apple/swift/pull/7125 
> 
> 
> Jordan
> 
>> On Mar 9, 2017, at 17:59, David Sweeris via swift-users 
>> > wrote:
>> 
>> If my type doesn’t know/care about the difference between a normal “String" 
>> and an “ExtendedClusterScalarGraphemeLiteralUnicodeTypeCluster” (or whatever 
>> those other literal types are called), is there anything wrong with doing 
>> this?
>> public protocol EasilyExpressibleByStringLiteral : 
>> ExpressibleByStringLiteral {
>> typealias StringLiteralType = String
>> }
>> extension EasilyExpressibleByStringLiteral where StringLiteralType == String 
>> {
>> public init(unicodeScalarLiteral value: String.UnicodeScalarLiteralType) 
>> {
>> self.init(stringLiteral: String(describing: value))
>> }
>> public init(extendedGraphemeClusterLiteral value: 
>> String.ExtendedGraphemeClusterLiteralType) {
>> self.init(stringLiteral: String(describing: value))
>> }
>> }
>> because then I only have to write the one init function:
>> public struct MyType : EasilyExpressibleByStringLiteral {
>> public init(stringLiteral value: StringLiteralType) {...}
>> }
>> and the compiler will stop complaining about my type not conforming to the 
>> other two protocols. Because I’ve scanned the docs, and I can’t even figure 
>> out how to create an ExtendedGraphemeClusterLiteral, let alone come up with 
>> a reason why I’d want to treat it differently than a regular String when 
>> using it to initialize an instance of MyType.
>> 
>> - Dave Sweeris
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Quick Question about ExpressibleByStringLiteral

2017-03-09 Thread Jordan Rose via swift-users
Andrew Bennett is two steps ahead of you. :-) 
https://github.com/apple/swift/pull/7125 


Jordan

> On Mar 9, 2017, at 17:59, David Sweeris via swift-users 
>  wrote:
> 
> If my type doesn’t know/care about the difference between a normal “String" 
> and an “ExtendedClusterScalarGraphemeLiteralUnicodeTypeCluster” (or whatever 
> those other literal types are called), is there anything wrong with doing 
> this?
> public protocol EasilyExpressibleByStringLiteral : ExpressibleByStringLiteral 
> {
> typealias StringLiteralType = String
> }
> extension EasilyExpressibleByStringLiteral where StringLiteralType == String {
> public init(unicodeScalarLiteral value: String.UnicodeScalarLiteralType) {
> self.init(stringLiteral: String(describing: value))
> }
> public init(extendedGraphemeClusterLiteral value: 
> String.ExtendedGraphemeClusterLiteralType) {
> self.init(stringLiteral: String(describing: value))
> }
> }
> because then I only have to write the one init function:
> public struct MyType : EasilyExpressibleByStringLiteral {
> public init(stringLiteral value: StringLiteralType) {...}
> }
> and the compiler will stop complaining about my type not conforming to the 
> other two protocols. Because I’ve scanned the docs, and I can’t even figure 
> out how to create an ExtendedGraphemeClusterLiteral, let alone come up with a 
> reason why I’d want to treat it differently than a regular String when using 
> it to initialize an instance of MyType.
> 
> - Dave Sweeris
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Quick Question about ExpressibleByStringLiteral

2017-03-09 Thread David Sweeris via swift-users
If my type doesn’t know/care about the difference between a normal “String" and 
an “ExtendedClusterScalarGraphemeLiteralUnicodeTypeCluster” (or whatever those 
other literal types are called), is there anything wrong with doing this?
public protocol EasilyExpressibleByStringLiteral : ExpressibleByStringLiteral {
typealias StringLiteralType = String
}
extension EasilyExpressibleByStringLiteral where StringLiteralType == String {
public init(unicodeScalarLiteral value: String.UnicodeScalarLiteralType) {
self.init(stringLiteral: String(describing: value))
}
public init(extendedGraphemeClusterLiteral value: 
String.ExtendedGraphemeClusterLiteralType) {
self.init(stringLiteral: String(describing: value))
}
}
because then I only have to write the one init function:
public struct MyType : EasilyExpressibleByStringLiteral {
public init(stringLiteral value: StringLiteralType) {...}
}
and the compiler will stop complaining about my type not conforming to the 
other two protocols. Because I’ve scanned the docs, and I can’t even figure out 
how to create an ExtendedGraphemeClusterLiteral, let alone come up with a 
reason why I’d want to treat it differently than a regular String when using it 
to initialize an instance of MyType.

- Dave Sweeris___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users