Skip to content

Commit

Permalink
Merge pull request #255 from ankurp/xcode-9-swift-4
Browse files Browse the repository at this point in the history
Adding support for Xcode 9/Swift 4
  • Loading branch information
ankurp authored Sep 21, 2017
2 parents bd0fdd2 + c57b938 commit ac2f33d
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 207 deletions.
2 changes: 1 addition & 1 deletion .swift-sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "sandbox",
"title": "Dollar",
"description": "Learn to use Dollar",
"swiftversion": "swift-3.0-RELEASE-ubuntu14.04",
"swiftversion": "swift-4.0-RELEASE-ubuntu14.04",
"giturl": "https://github.com/ankurp/DollarSwiftPackageSample",
"gittag": "1.0.0"
}
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1
4.0
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode8
osx_image: xcode9

script:
- swift build
Expand Down
2 changes: 1 addition & 1 deletion Dollar.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Dollar"
s.version = "6.2.1"
s.version = "7.0.0"
s.summary = "A functional tool-belt for Swift Language"
s.homepage = "https://github.com/ankurp/Dollar"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
22 changes: 17 additions & 5 deletions Dollar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
__PBXFileRef_Tests/DollarTests/DollarTests.swift /* DollarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DollarTests.swift; sourceTree = "<group>"; };
__PBXFileRef_scripts /* scripts */ = {isa = PBXFileReference; lastKnownFileType = folder; path = scripts; sourceTree = "<group>"; };
"_____Product_Dollar" /* Dollar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Dollar.framework; sourceTree = BUILT_PRODUCTS_DIR; };
"_____Product_DollarTests" /* DollarTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = DollarTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
"_____Product_DollarTests" /* DollarTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = DollarTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -174,6 +174,14 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 9999;
TargetAttributes = {
"______Target_Dollar" = {
LastSwiftMigration = 0900;
};
"______Target_DollarTests" = {
LastSwiftMigration = 0900;
};
};
};
buildConfigurationList = "___RootConfs_" /* Build configuration list for PBXProject "Dollar" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -236,7 +244,8 @@
PRODUCT_BUNDLE_IDENTIFIER = Dollar;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -249,7 +258,8 @@
LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -266,7 +276,8 @@
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -280,7 +291,8 @@
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ Dollar is a Swift library that provides useful functional programming helper met

# Setup #

## Using [Carthage](https://github.com/Carthage/Carthage)

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)

## Using [cocoapods](http://cocoapods.org/) version 0.36.x or greater

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.
Expand All @@ -46,7 +42,7 @@ Still stuck. Then checkout this screencast on [how to import](http://recordit.co

## Support for Xcode and Swift

* For Xcode 9 (Swift 4) use branch [`xcode-9-swift-4`](https://github.com/ankurp/Dollar/pull/255)
* For Xcode 9 (Swift 4) use version `7.0.0`
* For Xcode 8 (Swift 3) use version `6.2.1`
* For Xcode 7 (Swift 2) use version `4.1.0` or `5.2.0`
* For Xcode 6.3 (Swift 1.2) use version `3.0.3`
Expand Down
4 changes: 2 additions & 2 deletions Sources/AutoBind.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This is an autogenerated file. Do not edit this file manually.

public extension $ {
public extension `$` {

public class func bind<T1, R>(f: @escaping (T1) -> R, _ t1: T1) -> (() -> R) {
return { f(t1) }
Expand Down Expand Up @@ -52,4 +52,4 @@ public extension $ {
}


}
}
4 changes: 2 additions & 2 deletions Sources/AutoCurry.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This is an autogenerated file. Do not edit this file manually.

public extension $ {
public extension `$` {

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


}
}
62 changes: 31 additions & 31 deletions Sources/Dollar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Foundation
import Dispatch
#endif

open class $ {
open class `$` {
/// ___ ___ _______ ___ ________ _______ ________
/// |\ \|\ \|\ ___ \ |\ \ |\ __ \|\ ___ \ |\ __ \
/// \ \ \\\ \ \ __/|\ \ \ \ \ \|\ \ \ __/|\ \ \|\ \
Expand Down Expand Up @@ -139,8 +139,8 @@ open class $ {
/// - returns: A function that can be called with variadic parameters of values
open class func compose<T>(_ functions: ((T...) -> [T])...) -> ((T...) -> [T]) {
typealias Function = ([T]) -> [T]
return {
var result = $0
return { (result: T...) -> [T] in
var result = result
for fun in functions {
let f = unsafeBitCast(fun, to: Function.self)
result = f(result)
Expand Down Expand Up @@ -240,7 +240,7 @@ open class $ {
/// - parameter arrays: The arrays to difference between.
/// - returns: The difference between the first array and all the remaining arrays from the arrays params.
open class func differenceInOrder<T: Equatable>(_ arrays: [[T]]) -> [T] {
return $.reduce(self.rest(arrays), initial: self.first(arrays)!) { (result, arr) -> [T] in
return `$`.reduce(self.rest(arrays), initial: self.first(arrays)!) { (result, arr) -> [T] in
return result.filter() { !arr.contains($0) }
}
}
Expand Down Expand Up @@ -359,7 +359,7 @@ open class $ {
/// - returns: factorial
open class func factorial(_ num: Int) -> Int {
guard num > 0 else { return 1 }
return num * $.factorial(num - 1)
return num * `$`.factorial(num - 1)
}

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

if index != randIndex {
Swift.swap(&newArr[index], &newArr[randIndex])
newArr.swapAt(index, randIndex)
}
}
return newArr
Expand All @@ -579,7 +579,7 @@ open class $ {
/// - parameter array: The array to source from.
/// - parameter function: The function to get value of the key for each element to group by.
/// - returns: Dictionary that contains the key generated from the element passed in the function.
open class func frequencies<T, U: Equatable>(_ array: [T], function: (T) -> U) -> [U: Int] {
open class func frequencies<T, U>(_ array: [T], function: (T) -> U) -> [U: Int] {
var result = [U: Int]()
for elem in array {
let key = function(elem)
Expand Down Expand Up @@ -612,7 +612,7 @@ open class $ {
/// - parameter second: number
/// - returns: Least common multiple
open class func lcm(_ first: Int, _ second: Int) -> Int {
return (first / $.gcd(first, second)) * second
return (first / `$`.gcd(first, second)) * second
}

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

Expand Down Expand Up @@ -1056,7 +1056,7 @@ open class $ {
for index in indices {
elemToRemove.append(array[index])
}
return $.pull(array, values: elemToRemove)
return `$`.pull(array, values: elemToRemove)
}

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

let strings = self.permutation($.initial(elements))
if let char = $.last(elements) {
return $.reduce(strings, initial: []) { (result, str) -> [String] in
let splitStr = $.map(str.description.characters) { $0.description }
return result + $.map(0...splitStr.count) { (index) -> String in
var copy = $.copy(splitStr)
let strings = self.permutation(`$`.initial(elements))
if let char = `$`.last(elements) {
return `$`.reduce(strings, initial: []) { (result, str) -> [String] in
let splitStr = `$`.map(str.description.characters) { $0.description }
return result + `$`.map(0...splitStr.count) { (index) -> String in
var copy = `$`.copy(splitStr)
copy.insert(char.description, at: (splitStr.count - index))
return $.join(copy, separator: "")
return `$`.join(copy, separator: "")
}
}.sorted()
}
Expand Down Expand Up @@ -1110,7 +1110,7 @@ open class $ {
/// - parameter from: Start value of range
/// - parameter to: End value of range
/// - returns: Array of elements based on the sequence that is incremented by 1
open class func range<T: Strideable>(from startVal: T, to endVal: T) -> [T] where T.Stride : ExpressibleByIntegerLiteral {
open class func range<T: Strideable>(from startVal: T, to endVal: T) -> [T] {
return self.range(from: startVal, to: endVal, incrementBy: 1)
}

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

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

/// Reduce function that will resolve to one value after performing combine function on all elements
Expand Down Expand Up @@ -1263,7 +1263,7 @@ open class $ {
///
/// - parameter num: Number of times to call function
/// - parameter function: The function to be called every time
open class func times(_ num: Int, function: (Void) -> Void) {
open class func times(_ num: Int, function: @escaping () -> Void) {
_ = self.times(num) { (index: Int) -> () in
function()
}
Expand Down Expand Up @@ -1462,29 +1462,29 @@ open class Chain<C> {
///
/// - returns: First element from the array.
open func first() -> C? {
return $.first(self.value)
return `$`.first(self.value)
}

/// Get the second object in the wrapper object.
///
/// - returns: Second element from the array.
open func second() -> C? {
return $.second(self.value)
return `$`.second(self.value)
}

/// Get the third object in the wrapper object.
///
/// - returns: Third element from the array.
open func third() -> C? {
return $.third(self.value)
return `$`.third(self.value)
}

/// Flattens nested array.
///
/// - returns: The wrapper object.
open func flatten() -> Chain {
return self.queue {
return Wrapper($.flatten($0.value))
return Wrapper(`$`.flatten($0.value))
}
}

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

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

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

Expand Down
Loading

0 comments on commit ac2f33d

Please sign in to comment.