Dot notation as shorthand in subscripts and functions


(Vatsal Manot) #1

-1 from me. The problems you’ve mentioned can either easily be overcome via extensions, or aren’t big enough to justify the new syntax.

I have personally encountered one of the problems you are describing, and the following is how I resolved it:

extension MutableCollectionType
{
    public var first: Generator.Element?
    {
        get
        {
            return first
        }
        
        set
        {
            if !isEmpty, let newValue = newValue
            {
                self[startIndex] = newValue
            }
        }
    }
}

var array: [Int] = [0, 2, 3, 4, 5]

array.first
array.first = 1