Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-11 Thread Glen Huang via swift-users
Thanks for the detailed example. It makes sense. But the code can grow pretty quickly with just a few methods and a few concrete types. Also most are repetitive. I’ll try to incorporate this pattern when the use case is simple. But for more complex ones I guess I have to stick with classes for

Re: [swift-users] Swift linux repl can't import

2017-07-11 Thread Mason Mark via swift-users
I'm reviving this somewhat-old thread because it's still the most prominent search result when googling this issue to debug it (other than the below-referenced SR-3648). The workaround of using -I to pass an include path to swift was working for me, because as noted by Will Stanton below, the i

Re: [swift-users] Is there any harm that an @escaping handler never called?

2017-07-11 Thread Zhao Xin via swift-users
Glad to know the answer. And thank you, Slava and Daniel.​ Zhao Xin On Wed, Jul 12, 2017 at 7:53 AM, Daniel Dunbar wrote: > > On Jul 11, 2017, at 3:55 PM, Zhao Xin via swift-users < > swift-users@swift.org> wrote: > > For example, I have an async query, I pass it an `@escaping > resultHandler`.

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-11 Thread Howard Lovatt via swift-users
I would be tempted to use classes for this if you can use single inheritance. If you need multiple inheritance then use an enum and hand code the dispatch, a lot more work :(. E.G.: protocol A { func a() -> String } protocol B { func b() -> String } struct AB1: A, B, Hashable { func a(

Re: [swift-users] Is there any harm that an @escaping handler never called?

2017-07-11 Thread Daniel Dunbar via swift-users
> On Jul 11, 2017, at 3:55 PM, Zhao Xin via swift-users > wrote: > > For example, I have an async query, I pass it an `@escaping resultHandler`. > If there is any results, the handler will run. However, if the result is > empty, the `@escaping resultHandler` will

Re: [swift-users] Is there any harm that an @escaping handler never called?

2017-07-11 Thread Slava Pestov via swift-users
No, there is no requirement to invoke a closure at least once, escaping or not. Slava > On Jul 11, 2017, at 3:55 PM, Zhao Xin via swift-users > wrote: > > For example, I have an async query, I pass it an `@escaping resultHandler`. > If there is any results, the handler will run. However, if t

[swift-users] Is there any harm that an @escaping handler never called?

2017-07-11 Thread Zhao Xin via swift-users
For example, I have an async query, I pass it an `@escaping resultHandler`. If there is any results, the handler will run. However, if the result is empty, the `@escaping resultHandler` will never run. Is there any memory leak or something will happen if the `@escaping resultHandler` never runs?

[swift-users] Public extension method in extension with internal requirements

2017-07-11 Thread Taylor Swift via swift-users
I have several public structs that conform to this internal protocol. The protocol has an associated type IntV so that it can service 2, 3, or 4 dimensional noise. protocol HashedTilingNoise { associatedtype IntV var amplitude:Double { get } var frequency:Double { get } var wavele

Re: [swift-users] Exceptional values in the Comparable protocol

2017-07-11 Thread Dave Abrahams via swift-users
on Tue Jul 11 2017, Martin R wrote: > Thank you for the clarification! Sure, happy to help! -- -Dave ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

Re: [swift-users] Exceptional values in the Comparable protocol

2017-07-11 Thread Martin R via swift-users
Thank you for the clarification! > On 10. Jul 2017, at 23:29, Dave Abrahams via swift-users > wrote: > > > on Sun Jul 09 2017, Martin R wrote: > >> The Comparable protocol requires that < and == impose a strict total >> order: exactly one of a==b, ab must hold for all values a and b >> of a

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-11 Thread Adrian Zubarev via swift-users
No it does not have to be a generic enum at all, as long you do not want extending the types from a diffrent module. Simply add a new enum case for each type you need, like `case string(String)`. You may also want to ask the wrapped type for it's hashValue so that it will hash correctly. -- A

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-11 Thread Glen Huang via swift-users
On second thought, this doesn’t seem to solve the problem. Because once I extract the value out, they’re of different types. I can’t uniformly treat them as Named and process them. Unless I got the enum definition wrong. Sorry for the quick-fire mails. > On 11 Jul 2017, at 9:15 PM, Glen Huang

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-11 Thread Glen Huang via swift-users
NM, I think you meant this? enum Either { case Left(T1) case Right(T2) } > On 11 Jul 2017, at 9:06 PM, Glen Huang via swift-users > wrote: > > This sounds pretty interesting. > > But I can’t totally wrap my head around it. How do I "wrap types into enum > cases”? Could you provide a

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-11 Thread Glen Huang via swift-users
This sounds pretty interesting. But I can’t totally wrap my head around it. How do I "wrap types into enum cases”? Could you provide a sample code? Thanks. > On 11 Jul 2017, at 8:50 PM, Adrian Zubarev > wrote: > > If the solution you seek is not designed so that the module user can extend >

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-11 Thread Adrian Zubarev via swift-users
If the solution you seek is not designed so that the module user can extend the set of types then you could wrap your types into enum cases and use the enum for your set. ;) When Swift will support anonymous enum cases, this will be an elegant solution to these type of things. -- Adrian Zub

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-11 Thread Glen Huang via swift-users
Thanks for bringing AnyHashable to my attention. It works, but the types are now erased. I want to have a union of the two sets because I want to loop over it to treat each contained item as Named, so I can process them as though they are of the same type. Is this type of use case really should

[swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-11 Thread Glen Huang via swift-users
Hi, I want to store some heterogeneous items all conform to a protocol inside a set, is it something possible to do in swift? I tried this example: ``` protocol Named: Hashable { var name: String { get } } extension Named { var hashValue: Int { return name.hashValue } stat