From 5ec842d225872c9ca7dc26b94e20ebca6790f341 Mon Sep 17 00:00:00 2001 From: tsk takezawa Date: Sun, 21 Jun 2015 15:04:29 +0900 Subject: [PATCH] Support operator of push an element to the array #114 --- ExSwift/Array.swift | 7 +++++++ ExSwiftTests/ArrayExtensionsTests.swift | 7 +++++++ README.md | 1 + 3 files changed, 15 insertions(+) diff --git a/ExSwift/Array.swift b/ExSwift/Array.swift index 80287d5..cc32468 100644 --- a/ExSwift/Array.swift +++ b/ExSwift/Array.swift @@ -1361,6 +1361,13 @@ internal extension Array { } +/** + Push an element to the array +*/ +public func += (inout first: [T], second: T) { + first.append(second) +} + /** Remove an element from the array */ diff --git a/ExSwiftTests/ArrayExtensionsTests.swift b/ExSwiftTests/ArrayExtensionsTests.swift index 8a50b22..1b30ddd 100644 --- a/ExSwiftTests/ArrayExtensionsTests.swift +++ b/ExSwiftTests/ArrayExtensionsTests.swift @@ -516,6 +516,13 @@ class ArrayExtensionsSpec: QuickSpec { } + it("operator") { + + self.intArray += 20 + + expect(self.intArray.last) == 20 + } + } /** diff --git a/README.md b/README.md index c5d5604..1a33f73 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ Name | Signatures #### Operators #### Name | Signature | Function ---- | --------- | -------- +`+=`|`+= (first: T, second: Array)`|Push `-`|`- (first: Array, second: Array) -> Array`|Difference `-`|`- (first: Array, second: T) -> Array`|Element removal `&`|`& (first: Array, second: Array) -> Array`|Intersection