> On 8 Jun 2016, at 20:53, Dave Abrahams via swift-evolution 
> <[email protected]> wrote:
> 
>> on Wed Jun 08 2016, Haravikk <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> But those shouldn't be the public names.  Perhaps s/box/wrap/ ?

True! So I’m thinking I’ll try to come up with a basic proposal soon, I’m just 
thinking about how this would be implemented. For example, it may make sense to 
do this as a protocol that AnyIndex (and other suitable types) can just conform 
to like so:

        protocol Unwrappable {
                associatedtype UnwrappedType
                func unwrap<T:UnwrappedType>() -> T?
                func unsafeUnwrap<T:UnwrappedType>() -> T
        }

I’ve kept the ability to specify a root type that unwrapping can produce, i.e- 
Comparable in the case of AnyIndex. Not too happy with the name of 
UnwrappedType, since it’s not intended to be the exact type in most cases, not 
sure what would be a more appropriate name. Also I lost track of the discussion 
about common root types between value and reference types; is there a type in 
Swift that could be used when unwrapping can produce absolutely anything 
(struct, enum, object etc.)? If not it may be better to drop the associated 
type and just lose the extra type-checking benefit.


I’m still struggling to come up with other types that definitely need this, as 
all the other AnyFoo types I can think of expose functionality of the 
underlying type that you can use, so the need to unwrap them doesn’t really 
come up. But with a protocol defining this the capability will be there to 
expand this quickly to other types later.
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to