<< Operator to append to array


(James Campbell) #1

I already have an implementation:

func <<<T>(var left: Array<T>, right:T)

{

    left.append(right)

}

It makes

myArray.append(myArrayItem)

become:

myArray << myArrayItem

Which is shorter and a lot of languages such as Ruby already use this.

···

--
 Wizard
james@supmenow.com
+44 7523 279 698


(Paul Ossenbruggen) #2

You can do this already

left += [right]

···

On Dec 21, 2015, at 9:22 AM, James Campbell via swift-evolution <swift-evolution@swift.org> wrote:

I already have an implementation:

func <<<T>(var left: Array<T>, right:T)

{

    left.append(right)

}

It makes

myArray.append(myArrayItem)

become:

myArray << myArrayItem

Which is shorter and a lot of languages such as Ruby already use this.

--
 Wizard
james@supmenow.com <mailto:james@supmenow.com>
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Paul Ossenbruggen) #3

I should have said

myArray += [myArrayItem]

···

On Dec 21, 2015, at 9:28 AM, Paul Ossenbruggen <possen@gmail.com> wrote:

You can do this already

left += [right]

On Dec 21, 2015, at 9:22 AM, James Campbell via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I already have an implementation:

func <<<T>(var left: Array<T>, right:T)

{

    left.append(right)

}

It makes

myArray.append(myArrayItem)

become:

myArray << myArrayItem

Which is shorter and a lot of languages such as Ruby already use this.

--
 Wizard
james@supmenow.com <mailto:james@supmenow.com>
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution


(James Campbell) #4

Ohh didn't know that :slight_smile:

···

On Mon, Dec 21, 2015 at 5:30 PM, Paul Ossenbruggen <possen@gmail.com> wrote:

I should have said

myArray += [myArrayItem]

On Dec 21, 2015, at 9:28 AM, Paul Ossenbruggen <possen@gmail.com> wrote:

You can do this already

left += [right]

On Dec 21, 2015, at 9:22 AM, James Campbell via swift-evolution < > swift-evolution@swift.org> wrote:

I already have an implementation:

func <<<T>(var left: Array<T>, right:T)

{

    left.append(right)

}

It makes

myArray.append(myArrayItem)

become:

myArray << myArrayItem

Which is shorter and a lot of languages such as Ruby already use this.

--
 Wizard
james@supmenow.com
+44 7523 279 698
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
 Wizard
james@supmenow.com
+44 7523 279 698