Skip to content

Commit

Permalink
Updating code to fix project and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurp committed Aug 8, 2014
1 parent f31fc10 commit 7dc08c3
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 165 deletions.
2 changes: 1 addition & 1 deletion Cent/Cent/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension Dictionary {
public mutating func merge<K, V>(dictionaries: Dictionary<K, V>...) {
for dict in dictionaries {
for (key, value) in dict {
self.updateValue(value as ValueType, forKey: key as KeyType)
self.updateValue(value as Value, forKey: key as Key)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Cent/Cent/Range.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ extension Range {

}

@infix func ==<T: ForwardIndex>(left: Range<T>, right: Range<T>) -> Bool {
func ==<T: ForwardIndexType>(left: Range<T>, right: Range<T>) -> Bool {
return left.startIndex == right.startIndex && left.endIndex == right.endIndex
}
76 changes: 39 additions & 37 deletions Dollar.playground/section-1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Dollar {
//

private var resultArray: [AnyObject] = []

private var lazyQueue: [(AnyObject) -> (AnyObject?)] = []

/// Initializer of the wrapper object for chaining.
Expand Down Expand Up @@ -171,7 +171,7 @@ public class Dollar {
return self.queue {
var result: [AnyObject] = []
for elem : AnyObject in $0 as [AnyObject] {
result += function(elem)
result.append(function(elem))
}
return result
}
Expand All @@ -185,7 +185,7 @@ public class Dollar {
return self.queue {
var result: [AnyObject] = []
for (index, elem : AnyObject) in enumerate($0 as [AnyObject]) {
result += function(index, elem)
result.append(function(index, elem))
}
return result
}
Expand Down Expand Up @@ -295,8 +295,9 @@ public class Dollar {
public class func after<T, E>(n: Int, function: (T...) -> E) -> ((T...) -> E?) {
var counter = n
return { (params: (T...)) -> E? in
typealias TType = (T...)
if --counter <= 0 {
return function(reinterpretCast(params))
return function(unsafeBitCast(params, TType.self))
}
return nil
}
Expand Down Expand Up @@ -333,7 +334,7 @@ public class Dollar {
public class func at<T>(array: [T], indexes: [Int]) -> [T] {
var result: [T] = []
for index in indexes {
result += array[index]
result.append(array[index])
}
return result
}
Expand All @@ -345,7 +346,8 @@ public class Dollar {
/// :return A new function that when called will invoked the passed function with the parameters specified.
public class func bind<T, E>(function: (T...) -> E, _ parameters: T...) -> (() -> E) {
return { () -> E in
return function(reinterpretCast(parameters))
typealias TType = (T...)
return function(unsafeBitCast(parameters, TType.self))
}
}

Expand All @@ -357,7 +359,7 @@ public class Dollar {
var result: [T] = []
for elem in array {
if let val = elem {
result += val
result.append(val)
}
}
return result
Expand All @@ -383,7 +385,7 @@ public class Dollar {
}
return newArr
}

/// Creates an array excluding all values of the provided arrays.
///
/// :param arrays The arrays to difference between.
Expand All @@ -408,7 +410,7 @@ public class Dollar {
}
for (key, count) in map {
for _ in 0..<count {
result += key
result.append(key)
}
}
return result
Expand Down Expand Up @@ -607,7 +609,7 @@ public class Dollar {
if let val = elem as? [AnyObject] {
resultArr += self.flatten(val)
} else {
resultArr += elem
resultArr.append(elem)
}
}
return resultArr
Expand Down Expand Up @@ -685,7 +687,7 @@ public class Dollar {
var result: [T] = []
if (array.count > numElements) {
for index in 0..<(array.count - numElements) {
result += array[index]
result.append(array[index])
}
}
return result
Expand All @@ -710,7 +712,7 @@ public class Dollar {
let count = arrays.count
for (key, value) in map {
if value == count {
result += key
result.append(key)
}
}
return result
Expand All @@ -721,8 +723,8 @@ public class Dollar {
/// :param array The array to join the elements of.
/// :param separator The separator to join the elements with.
/// :return Joined element from the array of elements.
public class func join<T: ExtensibleCollection>(array: [T], separator: T) -> T {
return Swift.join(separator, reinterpretCast(array) as [T])
public class func join<T: ExtensibleCollectionType>(array: [T], separator: T) -> T {
return Swift.join(separator, array)
}

/// Creates an array of keys given a dictionary.
Expand Down Expand Up @@ -868,7 +870,8 @@ public class Dollar {
/// :return First element from the array.
public class func partial<T, E> (function: (T...) -> E, _ parameters: T...) -> ((T...) -> E) {
return { (params: T...) -> E in
return function(reinterpretCast(parameters + params))
typealias TType = (T...)
return function(unsafeBitCast(parameters + params, TType.self))
}
}

Expand All @@ -881,13 +884,13 @@ public class Dollar {
/// :return Array partitioned into n element arrays, starting step elements apart.
public class func partition<T>(array: [T], var n: Int, var step: Int? = nil) -> [[T]] {
var result = [[T]]()
if !step? { step = n } // If no step is supplied move n each step.
if step != .None { step = n } // If no step is supplied move n each step.
if step < 1 { step = 1 } // Less than 1 results in an infinite loop.
if n < 1 { n = 0 } // Allow 0 if user wants [[],[],[]] for some reason.
if n > array.count { return [[]] }

for i in self.range(0, endVal: array.count - n, incrementBy: step!) {
result += Array(array[i..<(i+n)] as Slice<T>)
result.append(Array(array[i..<(i+n)] as Slice<T>))
}
return result
}
Expand All @@ -903,21 +906,21 @@ public class Dollar {
/// :return Array partitioned into n element arrays, starting step elements apart.
public class func partition<T>(var array: [T], var n: Int, var step: Int? = nil, pad: [T]?) -> [[T]] {
var result : [[T]] = []
if !step? { step = n } // If no step is supplied move n each step.
if step? != .None { step = n } // If no step is supplied move n each step.
if step < 1 { step = 1 } // Less than 1 results in an infinite loop.
if n < 1 { n = 0 } // Allow 0 if user wants [[],[],[]] for some reason.

for i in self.range(0, endVal: array.count, incrementBy: step!) {
var end = i+n
if end > array.count { end = array.count }
result += Array(array[i..<end] as Slice<T>)
result.append(Array(array[i..<end] as Slice<T>))
if end != i+n { break }
}

if let padding = pad {
let remain = array.count%n
let remain = array.count % n
let end = padding.count > remain ? remain : padding.count
result[result.count-1] += Array(padding[0..<end] as Slice<T>)
result[result.count - 1] += Array(padding[0..<end] as Slice<T>)
}
return result
}
Expand All @@ -930,14 +933,14 @@ public class Dollar {
/// :return Array partitioned into n element arrays, starting step elements apart.
public class func partitionAll<T>(array: [T], var n: Int, var step: Int? = nil) -> [[T]] {
var result = [[T]]()
if !step? { step = n } // If no step is supplied move n each step.
if step? != .None { step = n } // If no step is supplied move n each step.
if step < 1 { step = 1 } // Less than 1 results in an infinite loop.
if n < 1 { n = 0 } // Allow 0 if user wants [[],[],[]] for some reason.

for i in self.range(0, endVal: array.count, incrementBy: step!) {
var end = i+n
if end > array.count { end = array.count }
result += Array(array[i..<end] as Slice<T>)
result.append(Array(array[i..<end] as Slice<T>))
}
return result
}
Expand All @@ -955,7 +958,7 @@ public class Dollar {
let value = function(item)

if value == lastValue? {
result[result.count-1] += item
result[result.count-1].append(item)
} else {
result.append([item])
lastValue = value
Expand Down Expand Up @@ -986,7 +989,7 @@ public class Dollar {
var result : [E] = []
for obj in array {
if let val = obj[value] {
result += val
result.append(val)
}
}
return result
Expand Down Expand Up @@ -1051,8 +1054,8 @@ public class Dollar {
///
/// :param seq The sequence to generate from.
/// :return Array of elements generated from the sequence.
public class func sequence<S : Sequence>(seq: S) -> [S.GeneratorType.Element] {
return Array<S.GeneratorType.Element>(seq)
public class func sequence<S : SequenceType>(seq: S) -> [S.Generator.Element] {
return Array<S.Generator.Element>(seq)
}

/// Removes all elements from an array that the callback returns true.
Expand All @@ -1073,7 +1076,7 @@ public class Dollar {
var result : [T] = []
if (numElements < array.count) {
for index in numElements..<array.count {
result += array[index]
result.append(array[index])
}
}
return result
Expand Down Expand Up @@ -1162,7 +1165,7 @@ public class Dollar {
public class func times<T>(n: Int, function: (Int) -> T) -> [T] {
var result : [T] = []
for index in (0..<n) {
result += function(index)
result.append(function(index))
}
return result
}
Expand All @@ -1180,7 +1183,7 @@ public class Dollar {
}
var result : [T] = []
for key in map.keys {
result += key
result.append(key)
}
return result
}
Expand All @@ -1196,7 +1199,7 @@ public class Dollar {
}
var result : [T] = []
for key in map.keys {
result += key
result.append(key)
}
return result
}
Expand Down Expand Up @@ -1230,13 +1233,13 @@ public class Dollar {
var map : [T: Bool] = [T: Bool]()
for arr in arrays {
for elem in arr {
map[elem] = !map[elem]
map[elem] = !(map[elem] ?? false)
}
}
var result : [T] = []
for (key, value) in map {
if value {
result += key
result.append(key)
}
}
return result
Expand All @@ -1249,12 +1252,12 @@ public class Dollar {
/// :return An array of grouped elements.
public class func zip(arrays: [AnyObject]...) -> [AnyObject] {
var result: [[AnyObject]] = []
for _ in self.first(arrays) as [AnyObject] {
result += [] as [AnyObject]
for _ in self.first(arrays)! as [AnyObject] {
result.append([] as [AnyObject])
}
for (index, array) in enumerate(arrays) {
for (elemIndex, elem : AnyObject) in enumerate(array) {
result[elemIndex] += elem
result[elemIndex].append(elem)
}
}
return result
Expand All @@ -1276,4 +1279,3 @@ public class Dollar {

public typealias $ = Dollar


6 changes: 0 additions & 6 deletions Dollar.playground/section-2.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@

$.map([1, 2, 3]) {
$0 * 2
}

$.flatten([1, [3, 4]])

6 changes: 6 additions & 0 deletions Dollar.playground/timeline.xctimeline
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
<Timeline
version = "3.0">
<TimelineItems>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=45224&amp;EndingColumnNumber=22&amp;EndingLineNumber=1281&amp;StartingColumnNumber=0&amp;StartingLineNumber=1281&amp;Timestamp=429153910.362457">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=45224&amp;EndingColumnNumber=48&amp;EndingLineNumber=1281&amp;StartingColumnNumber=37&amp;StartingLineNumber=1281&amp;Timestamp=429153910.363025">
</LoggerValueHistoryTimelineItem>
</TimelineItems>
</Timeline>
Loading

0 comments on commit 7dc08c3

Please sign in to comment.