Skip to content

Commit

Permalink
Merge pull request #50 from ankurp/davidpdrsn-master
Browse files Browse the repository at this point in the history
Adding example and remove scheme files
  • Loading branch information
ankurp committed Jun 24, 2014
2 parents 516a864 + 94edb30 commit ea40c80
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Dollar/Dollar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ class $ {
return result
}

/// The identity function. Returns the argument it is given.
///
/// :param arg Value to return
/// :return Argument that was passed
class func id<T>(arg: T) -> T {
return arg
}

/// Gets the index at which the first occurrence of value is found.
///
/// :param array The array to source from.
Expand Down
6 changes: 6 additions & 0 deletions DollarTests/DollarTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class DollarTests: XCTestCase {
func testReduce() {
XCTAssertEqual($.reduce([1, 2, 3, 4, 5], initial: 0) { $0 + $1 }, 15, "Reduce function should sum elements in the array")
}


func testSlice() {
XCTAssertEqualObjects($.slice([1,2,3,4,5], start: 0, end: 2), [1, 2], "Slice subarray 0..2")
Expand Down Expand Up @@ -351,5 +352,10 @@ class DollarTests: XCTestCase {
let z = fibMemo(6)
XCTAssertEqualObjects(times, 1, "Function called 1 times due to memoize")
}


func testId() {
XCTAssertEqual($.id(1), 1, "Id should return the argument it gets passed")
}

}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Method | Usage
---- | ---------
**`$.after`**|Creates a function that executes passed function only after being called n times.
**`$.bind`**|Creates a function that, when called, invokes func with the binding of arguments provided.
**`$.id`**|The identify function which simply returns the argument its given.
**`$.partial`**|Creates a function that, when called, invokes func with any additional partial arguments prepended to those provided to the new function.
**`$.times`**|Call a function n times and also passes the index. If a value is returned in the function then the times method will return an array of those values.

Expand Down Expand Up @@ -662,6 +663,15 @@ helloWorldFunc()
=> "Hello World from Swift"
```

### id - `$.id`

The identify function which simply returns the argument its given.

```swift
$.id("Hello World from Swift")
=> "Hello World from Swift"
```

### partial - `$.partial`

Creates a function that, when called, invokes func with any additional partial arguments prepended to those provided to the new function.
Expand Down

0 comments on commit ea40c80

Please sign in to comment.