Skip to content

Commit

Permalink
Support operator of push an element to the array pNre#114
Browse files Browse the repository at this point in the history
  • Loading branch information
to4iki committed Jun 21, 2015
1 parent 864c6a2 commit 5ec842d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ExSwift/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,13 @@ internal extension Array {

}

/**
Push an element to the array
*/
public func += <T: Equatable> (inout first: [T], second: T) {
first.append(second)
}

/**
Remove an element from the array
*/
Expand Down
7 changes: 7 additions & 0 deletions ExSwiftTests/ArrayExtensionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,13 @@ class ArrayExtensionsSpec: QuickSpec {

}

it("operator") {

self.intArray += 20

expect(self.intArray.last) == 20
}

}

/**
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Name | Signatures
#### Operators ####
Name | Signature | Function
---- | --------- | --------
`+=`|`+= <T: Equatable> (first: T, second: Array<T>)`|Push
`-`|`- <T: Equatable> (first: Array<T>, second: Array<T>) -> Array<T>`|Difference
`-`|`- <T: Equatable> (first: Array<T>, second: T) -> Array<T>`|Element removal
`&`|`& <T: Equatable> (first: Array<T>, second: Array<T>) -> Array<T>`|Intersection
Expand Down

0 comments on commit 5ec842d

Please sign in to comment.