Skip to content

Commit ac2f33d

Browse files
authored
Merge pull request #255 from ankurp/xcode-9-swift-4
Adding support for Xcode 9/Swift 4
2 parents bd0fdd2 + c57b938 commit ac2f33d

File tree

10 files changed

+215
-207
lines changed

10 files changed

+215
-207
lines changed

.swift-sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"type": "sandbox",
33
"title": "Dollar",
44
"description": "Learn to use Dollar",
5-
"swiftversion": "swift-3.0-RELEASE-ubuntu14.04",
5+
"swiftversion": "swift-4.0-RELEASE-ubuntu14.04",
66
"giturl": "https://github.com/ankurp/DollarSwiftPackageSample",
77
"gittag": "1.0.0"
88
}

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1
1+
4.0

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: objective-c
2-
osx_image: xcode8
2+
osx_image: xcode9
33

44
script:
55
- swift build

Dollar.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Dollar"
3-
s.version = "6.2.1"
3+
s.version = "7.0.0"
44
s.summary = "A functional tool-belt for Swift Language"
55
s.homepage = "https://github.com/ankurp/Dollar"
66
s.license = { :type => "MIT", :file => "LICENSE" }

Dollar.xcodeproj/project.pbxproj

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
__PBXFileRef_Tests/DollarTests/DollarTests.swift /* DollarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DollarTests.swift; sourceTree = "<group>"; };
3636
__PBXFileRef_scripts /* scripts */ = {isa = PBXFileReference; lastKnownFileType = folder; path = scripts; sourceTree = "<group>"; };
3737
"_____Product_Dollar" /* Dollar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Dollar.framework; sourceTree = BUILT_PRODUCTS_DIR; };
38-
"_____Product_DollarTests" /* DollarTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = DollarTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
38+
"_____Product_DollarTests" /* DollarTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = DollarTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3939
/* End PBXFileReference section */
4040

4141
/* Begin PBXFrameworksBuildPhase section */
@@ -174,6 +174,14 @@
174174
isa = PBXProject;
175175
attributes = {
176176
LastUpgradeCheck = 9999;
177+
TargetAttributes = {
178+
"______Target_Dollar" = {
179+
LastSwiftMigration = 0900;
180+
};
181+
"______Target_DollarTests" = {
182+
LastSwiftMigration = 0900;
183+
};
184+
};
177185
};
178186
buildConfigurationList = "___RootConfs_" /* Build configuration list for PBXProject "Dollar" */;
179187
compatibilityVersion = "Xcode 3.2";
@@ -236,7 +244,8 @@
236244
PRODUCT_BUNDLE_IDENTIFIER = Dollar;
237245
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
238246
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
239-
SWIFT_VERSION = 3.0;
247+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
248+
SWIFT_VERSION = 4.0;
240249
};
241250
name = Release;
242251
};
@@ -249,7 +258,8 @@
249258
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
250259
OTHER_LDFLAGS = "$(inherited)";
251260
OTHER_SWIFT_FLAGS = "$(inherited)";
252-
SWIFT_VERSION = 3.0;
261+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
262+
SWIFT_VERSION = 4.0;
253263
};
254264
name = Release;
255265
};
@@ -266,7 +276,8 @@
266276
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
267277
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
268278
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
269-
SWIFT_VERSION = 3.0;
279+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
280+
SWIFT_VERSION = 4.0;
270281
};
271282
name = Debug;
272283
};
@@ -280,7 +291,8 @@
280291
OTHER_LDFLAGS = "$(inherited)";
281292
OTHER_SWIFT_FLAGS = "$(inherited)";
282293
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
283-
SWIFT_VERSION = 3.0;
294+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
295+
SWIFT_VERSION = 4.0;
284296
};
285297
name = Debug;
286298
};

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ Dollar is a Swift library that provides useful functional programming helper met
2121

2222
# Setup #
2323

24-
## Using [Carthage](https://github.com/Carthage/Carthage)
25-
26-
Add `github "ankurp/Dollar" ~> 6.2.1` to your `Cartfile` and run `carthage update`. If unfamiliar with Carthage then checkout their [Getting Started section](https://github.com/Carthage/Carthage#getting-started) or this [sample app](https://github.com/ankurp/DollarCarthageApp)
27-
2824
## Using [cocoapods](http://cocoapods.org/) version 0.36.x or greater
2925

3026
Add `pod 'Dollar'` to your `Podfile` and run `pod install`. Add `use_frameworks!` to the end of the `Podfile`. Also checkout this [sample app](https://github.com/ankurp/DollarPodApp). Requires cocoapod version 0.36.x or greater.
@@ -46,7 +42,7 @@ Still stuck. Then checkout this screencast on [how to import](http://recordit.co
4642

4743
## Support for Xcode and Swift
4844

49-
* For Xcode 9 (Swift 4) use branch [`xcode-9-swift-4`](https://github.com/ankurp/Dollar/pull/255)
45+
* For Xcode 9 (Swift 4) use version `7.0.0`
5046
* For Xcode 8 (Swift 3) use version `6.2.1`
5147
* For Xcode 7 (Swift 2) use version `4.1.0` or `5.2.0`
5248
* For Xcode 6.3 (Swift 1.2) use version `3.0.3`

Sources/AutoBind.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is an autogenerated file. Do not edit this file manually.
22

3-
public extension $ {
3+
public extension `$` {
44

55
public class func bind<T1, R>(f: @escaping (T1) -> R, _ t1: T1) -> (() -> R) {
66
return { f(t1) }
@@ -52,4 +52,4 @@ public extension $ {
5252
}
5353

5454

55-
}
55+
}

Sources/AutoCurry.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This is an autogenerated file. Do not edit this file manually.
22

3-
public extension $ {
3+
public extension `$` {
44

55
public class func curry<T1, T2, R>(_ f: @escaping (T1, T2) -> R) -> (T1) -> (T2) -> R {
66
return { t1 in { t2 in f(t1, t2) } }
@@ -47,4 +47,4 @@ public extension $ {
4747
}
4848

4949

50-
}
50+
}

Sources/Dollar.swift

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Foundation
2222
import Dispatch
2323
#endif
2424

25-
open class $ {
25+
open class `$` {
2626
/// ___ ___ _______ ___ ________ _______ ________
2727
/// |\ \|\ \|\ ___ \ |\ \ |\ __ \|\ ___ \ |\ __ \
2828
/// \ \ \\\ \ \ __/|\ \ \ \ \ \|\ \ \ __/|\ \ \|\ \
@@ -139,8 +139,8 @@ open class $ {
139139
/// - returns: A function that can be called with variadic parameters of values
140140
open class func compose<T>(_ functions: ((T...) -> [T])...) -> ((T...) -> [T]) {
141141
typealias Function = ([T]) -> [T]
142-
return {
143-
var result = $0
142+
return { (result: T...) -> [T] in
143+
var result = result
144144
for fun in functions {
145145
let f = unsafeBitCast(fun, to: Function.self)
146146
result = f(result)
@@ -240,7 +240,7 @@ open class $ {
240240
/// - parameter arrays: The arrays to difference between.
241241
/// - returns: The difference between the first array and all the remaining arrays from the arrays params.
242242
open class func differenceInOrder<T: Equatable>(_ arrays: [[T]]) -> [T] {
243-
return $.reduce(self.rest(arrays), initial: self.first(arrays)!) { (result, arr) -> [T] in
243+
return `$`.reduce(self.rest(arrays), initial: self.first(arrays)!) { (result, arr) -> [T] in
244244
return result.filter() { !arr.contains($0) }
245245
}
246246
}
@@ -359,7 +359,7 @@ open class $ {
359359
/// - returns: factorial
360360
open class func factorial(_ num: Int) -> Int {
361361
guard num > 0 else { return 1 }
362-
return num * $.factorial(num - 1)
362+
return num * `$`.factorial(num - 1)
363363
}
364364

365365
/// Get element from an array at the given index which can be negative
@@ -462,7 +462,7 @@ open class $ {
462462
/// - parameter array: The array to group
463463
/// - parameter callback: Function whose response will be used as a key in the new string
464464
/// - returns: grouped collection
465-
open class func groupBy<T, U: Hashable>(_ array: [T], callback: (T) -> U) -> [U: [T]] {
465+
open class func groupBy<T, U>(_ array: [T], callback: (T) -> U) -> [U: [T]] {
466466
var grouped = [U: [T]]()
467467
for element in array {
468468
let key = callback(element)
@@ -557,7 +557,7 @@ open class $ {
557557
let randIndex = self.random(index)
558558

559559
if index != randIndex {
560-
Swift.swap(&newArr[index], &newArr[randIndex])
560+
newArr.swapAt(index, randIndex)
561561
}
562562
}
563563
return newArr
@@ -579,7 +579,7 @@ open class $ {
579579
/// - parameter array: The array to source from.
580580
/// - parameter function: The function to get value of the key for each element to group by.
581581
/// - returns: Dictionary that contains the key generated from the element passed in the function.
582-
open class func frequencies<T, U: Equatable>(_ array: [T], function: (T) -> U) -> [U: Int] {
582+
open class func frequencies<T, U>(_ array: [T], function: (T) -> U) -> [U: Int] {
583583
var result = [U: Int]()
584584
for elem in array {
585585
let key = function(elem)
@@ -612,7 +612,7 @@ open class $ {
612612
/// - parameter second: number
613613
/// - returns: Least common multiple
614614
open class func lcm(_ first: Int, _ second: Int) -> Int {
615-
return (first / $.gcd(first, second)) * second
615+
return (first / `$`.gcd(first, second)) * second
616616
}
617617

618618
/// The identity function. Returns the argument it is given.
@@ -677,7 +677,7 @@ open class $ {
677677
/// - parameter index: to check if it is in range
678678
/// - parameter isIn: to check in
679679
/// - returns: true if it is in range otherwise false
680-
open class func it<T: Comparable>(_ index: T, isIn range: Range<T>) -> Bool {
680+
open class func it<T>(_ index: T, isIn range: Range<T>) -> Bool {
681681
return index >= range.lowerBound && index < range.upperBound
682682
}
683683

@@ -1056,7 +1056,7 @@ open class $ {
10561056
for index in indices {
10571057
elemToRemove.append(array[index])
10581058
}
1059-
return $.pull(array, values: elemToRemove)
1059+
return `$`.pull(array, values: elemToRemove)
10601060
}
10611061

10621062
/// Returns permutation of array
@@ -1065,17 +1065,17 @@ open class $ {
10651065
/// - returns: Array of permutation of the characters specified
10661066
open class func permutation<T>(_ elements: [T]) -> [String] where T : CustomStringConvertible {
10671067
guard elements.count > 1 else {
1068-
return $.map(elements) { $0.description }
1068+
return `$`.map(elements) { $0.description }
10691069
}
10701070

1071-
let strings = self.permutation($.initial(elements))
1072-
if let char = $.last(elements) {
1073-
return $.reduce(strings, initial: []) { (result, str) -> [String] in
1074-
let splitStr = $.map(str.description.characters) { $0.description }
1075-
return result + $.map(0...splitStr.count) { (index) -> String in
1076-
var copy = $.copy(splitStr)
1071+
let strings = self.permutation(`$`.initial(elements))
1072+
if let char = `$`.last(elements) {
1073+
return `$`.reduce(strings, initial: []) { (result, str) -> [String] in
1074+
let splitStr = `$`.map(str.description.characters) { $0.description }
1075+
return result + `$`.map(0...splitStr.count) { (index) -> String in
1076+
var copy = `$`.copy(splitStr)
10771077
copy.insert(char.description, at: (splitStr.count - index))
1078-
return $.join(copy, separator: "")
1078+
return `$`.join(copy, separator: "")
10791079
}
10801080
}.sorted()
10811081
}
@@ -1110,7 +1110,7 @@ open class $ {
11101110
/// - parameter from: Start value of range
11111111
/// - parameter to: End value of range
11121112
/// - returns: Array of elements based on the sequence that is incremented by 1
1113-
open class func range<T: Strideable>(from startVal: T, to endVal: T) -> [T] where T.Stride : ExpressibleByIntegerLiteral {
1113+
open class func range<T: Strideable>(from startVal: T, to endVal: T) -> [T] {
11141114
return self.range(from: startVal, to: endVal, incrementBy: 1)
11151115
}
11161116

@@ -1130,8 +1130,8 @@ open class $ {
11301130
/// - parameter from: Start value of range
11311131
/// - parameter through: End value of range
11321132
/// - returns: Array of elements based on the sequence that is incremented by 1
1133-
open class func range<T: Strideable>(from startVal: T, through endVal: T) -> [T] where T.Stride : ExpressibleByIntegerLiteral {
1134-
return self.range(from: startVal, to: endVal + 1, incrementBy: 1)
1133+
open class func range<T: Strideable>(from startVal: T, through endVal: T) -> [T] {
1134+
return self.range(from: startVal, to: endVal.advanced(by: 1), incrementBy: 1)
11351135
}
11361136

11371137
/// Creates an array of numbers (positive and/or negative) progressing from start up to but not including end.
@@ -1141,7 +1141,7 @@ open class $ {
11411141
/// - parameter incrementBy: Increment sequence by.
11421142
/// - returns: Array of elements based on the sequence.
11431143
open class func range<T: Strideable>(from startVal: T, through endVal: T, incrementBy: T.Stride) -> [T] {
1144-
return self.range(from: startVal, to: endVal + 1, incrementBy: incrementBy)
1144+
return self.range(from: startVal, to: endVal.advanced(by: 1), incrementBy: incrementBy)
11451145
}
11461146

11471147
/// Reduce function that will resolve to one value after performing combine function on all elements
@@ -1263,7 +1263,7 @@ open class $ {
12631263
///
12641264
/// - parameter num: Number of times to call function
12651265
/// - parameter function: The function to be called every time
1266-
open class func times(_ num: Int, function: (Void) -> Void) {
1266+
open class func times(_ num: Int, function: @escaping () -> Void) {
12671267
_ = self.times(num) { (index: Int) -> () in
12681268
function()
12691269
}
@@ -1462,29 +1462,29 @@ open class Chain<C> {
14621462
///
14631463
/// - returns: First element from the array.
14641464
open func first() -> C? {
1465-
return $.first(self.value)
1465+
return `$`.first(self.value)
14661466
}
14671467

14681468
/// Get the second object in the wrapper object.
14691469
///
14701470
/// - returns: Second element from the array.
14711471
open func second() -> C? {
1472-
return $.second(self.value)
1472+
return `$`.second(self.value)
14731473
}
14741474

14751475
/// Get the third object in the wrapper object.
14761476
///
14771477
/// - returns: Third element from the array.
14781478
open func third() -> C? {
1479-
return $.third(self.value)
1479+
return `$`.third(self.value)
14801480
}
14811481

14821482
/// Flattens nested array.
14831483
///
14841484
/// - returns: The wrapper object.
14851485
open func flatten() -> Chain {
14861486
return self.queue {
1487-
return Wrapper($.flatten($0.value))
1487+
return Wrapper(`$`.flatten($0.value))
14881488
}
14891489
}
14901490

@@ -1501,7 +1501,7 @@ open class Chain<C> {
15011501
/// - returns: The wrapper object.
15021502
open func initial(_ numElements: Int) -> Chain {
15031503
return self.queue {
1504-
return Wrapper($.initial($0.value, numElements: numElements))
1504+
return Wrapper(`$`.initial($0.value, numElements: numElements))
15051505
}
15061506
}
15071507

@@ -1574,7 +1574,7 @@ open class Chain<C> {
15741574
/// - parameter function: Function to tell whether element value is true or false.
15751575
/// - returns: Whether all elements are true according to func function.
15761576
open func all(_ function: (C) -> Bool) -> Bool {
1577-
return $.every(self.value, callback: function)
1577+
return `$`.every(self.value, callback: function)
15781578
}
15791579

15801580
/// Returns if any element in array is true based on the passed function.
@@ -1605,7 +1605,7 @@ open class Chain<C> {
16051605
/// - returns: The wrapper object.
16061606
open func slice(_ start: Int, end: Int = 0) -> Chain {
16071607
return self.queue {
1608-
return Wrapper($.slice($0.value, start: start, end: end))
1608+
return Wrapper(`$`.slice($0.value, start: start, end: end))
16091609
}
16101610
}
16111611

0 commit comments

Comments
 (0)