[swift-evolution] [Pitch] Non-class type requirements on protocols (eg : struct, : enum)
Mike Pearce
mike at dubdubdubdude.com
Sat Oct 22 19:51:26 CDT 2016
https://docs.docker.com/toolbox/toolbox_install_mac/
On 23 October 2016 at 06:56, T.J. Usiyan via swift-evolution <
swift-evolution at swift.org> wrote:
> Thanks for the heads up! It wasn't just meant for you. Use of a generic
> Result type is one of my motivating cases.
>
> 1. If multiple libraries declare a generic type like that, converting
> between them becomes a pain.
> 2. Specific result types are useful and appropriate in many, if not most,
> cases.
> 3. protocols and retroactive conformance could make this less challenging
>
> On Sat, Oct 22, 2016 at 3:42 PM, David Sweeris <davesweeris at mac.com>
> wrote:
>
>> Was not sending your reply only to me and not the list intentional? It’s
>> fine either way, I was just about to send this to the list when I realized
>> you’d only sent your reply to me, and I don’t want quote you somewhere if
>> you intentionally didn’t post there.
>>
>> On Oct 22, 2016, at 1:39 PM, T.J. Usiyan <griotspeak at gmail.com> wrote:
>>
>> I would actually hope otherwise. A real benefit of enums is compile time
>> guarantees. I am looking for a generic means to represent and handle a set
>> of possible outcomes. Not in the hopes of making everything fully generic
>> but lessening the redundant parts of dealing with, for example, Result
>> types.
>>
>>
>> I think you can do that now...
>> enum Result<Payload> {
>> case success(Payload)
>> case failure(Error)
>> }
>>
>> Then in your function…
>> func foo<T> (r: Result<T>) {
>> ...
>> switch r {
>> case .success(let p): ...
>> case .failure(let e): ...
>> }
>> ...
>> }
>>
>> Or am I just not understanding you?
>>
>> - Dave Sweeris
>>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161023/3ed5d670/attachment.html>
More information about the swift-evolution
mailing list