@@ -22,7 +22,7 @@ import Foundation
22
22
import Dispatch
23
23
#endif
24
24
25
- open class $ {
25
+ open class `$` {
26
26
/// ___ ___ _______ ___ ________ _______ ________
27
27
/// |\ \|\ \|\ ___ \ |\ \ |\ __ \|\ ___ \ |\ __ \
28
28
/// \ \ \\\ \ \ __/|\ \ \ \ \ \|\ \ \ __/|\ \ \|\ \
@@ -139,8 +139,8 @@ open class $ {
139
139
/// - returns: A function that can be called with variadic parameters of values
140
140
open class func compose< T> ( _ functions: ( ( T . . . ) -> [ T ] ) ... ) -> ( ( T . . . ) -> [ T ] ) {
141
141
typealias Function = ( [ T ] ) -> [ T ]
142
- return {
143
- var result = $0
142
+ return { ( result : T ... ) - > [ T ] in
143
+ var result = result
144
144
for fun in functions {
145
145
let f = unsafeBitCast ( fun, to: Function . self)
146
146
result = f ( result)
@@ -240,7 +240,7 @@ open class $ {
240
240
/// - parameter arrays: The arrays to difference between.
241
241
/// - returns: The difference between the first array and all the remaining arrays from the arrays params.
242
242
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
244
244
return result. filter ( ) { !arr. contains ( $0) }
245
245
}
246
246
}
@@ -359,7 +359,7 @@ open class $ {
359
359
/// - returns: factorial
360
360
open class func factorial( _ num: Int ) -> Int {
361
361
guard num > 0 else { return 1 }
362
- return num * $ . factorial( num - 1 )
362
+ return num * `$` . factorial ( num - 1 )
363
363
}
364
364
365
365
/// Get element from an array at the given index which can be negative
@@ -462,7 +462,7 @@ open class $ {
462
462
/// - parameter array: The array to group
463
463
/// - parameter callback: Function whose response will be used as a key in the new string
464
464
/// - 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 ] ] {
466
466
var grouped = [ U: [ T] ] ( )
467
467
for element in array {
468
468
let key = callback ( element)
@@ -557,7 +557,7 @@ open class $ {
557
557
let randIndex = self . random ( index)
558
558
559
559
if index != randIndex {
560
- Swift . swap ( & newArr [ index] , & newArr [ randIndex] )
560
+ newArr . swapAt ( index, randIndex)
561
561
}
562
562
}
563
563
return newArr
@@ -579,7 +579,7 @@ open class $ {
579
579
/// - parameter array: The array to source from.
580
580
/// - parameter function: The function to get value of the key for each element to group by.
581
581
/// - 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 ] {
583
583
var result = [ U: Int] ( )
584
584
for elem in array {
585
585
let key = function ( elem)
@@ -612,7 +612,7 @@ open class $ {
612
612
/// - parameter second: number
613
613
/// - returns: Least common multiple
614
614
open class func lcm( _ first: Int , _ second: Int ) -> Int {
615
- return ( first / $ . gcd( first, second) ) * second
615
+ return ( first / `$` . gcd ( first, second) ) * second
616
616
}
617
617
618
618
/// The identity function. Returns the argument it is given.
@@ -677,7 +677,7 @@ open class $ {
677
677
/// - parameter index: to check if it is in range
678
678
/// - parameter isIn: to check in
679
679
/// - 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 {
681
681
return index >= range. lowerBound && index < range. upperBound
682
682
}
683
683
@@ -1056,7 +1056,7 @@ open class $ {
1056
1056
for index in indices {
1057
1057
elemToRemove. append ( array [ index] )
1058
1058
}
1059
- return $ . pull( array, values: elemToRemove)
1059
+ return `$` . pull ( array, values: elemToRemove)
1060
1060
}
1061
1061
1062
1062
/// Returns permutation of array
@@ -1065,17 +1065,17 @@ open class $ {
1065
1065
/// - returns: Array of permutation of the characters specified
1066
1066
open class func permutation< T> ( _ elements: [ T ] ) -> [ String ] where T : CustomStringConvertible {
1067
1067
guard elements. count > 1 else {
1068
- return $ . map( elements) { $0. description }
1068
+ return `$` . map ( elements) { $0. description }
1069
1069
}
1070
1070
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)
1077
1077
copy. insert ( char. description, at: ( splitStr. count - index) )
1078
- return $ . join( copy, separator: " " )
1078
+ return `$` . join ( copy, separator: " " )
1079
1079
}
1080
1080
} . sorted ( )
1081
1081
}
@@ -1110,7 +1110,7 @@ open class $ {
1110
1110
/// - parameter from: Start value of range
1111
1111
/// - parameter to: End value of range
1112
1112
/// - 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 ] {
1114
1114
return self . range ( from: startVal, to: endVal, incrementBy: 1 )
1115
1115
}
1116
1116
@@ -1130,8 +1130,8 @@ open class $ {
1130
1130
/// - parameter from: Start value of range
1131
1131
/// - parameter through: End value of range
1132
1132
/// - 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 )
1135
1135
}
1136
1136
1137
1137
/// Creates an array of numbers (positive and/or negative) progressing from start up to but not including end.
@@ -1141,7 +1141,7 @@ open class $ {
1141
1141
/// - parameter incrementBy: Increment sequence by.
1142
1142
/// - returns: Array of elements based on the sequence.
1143
1143
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)
1145
1145
}
1146
1146
1147
1147
/// Reduce function that will resolve to one value after performing combine function on all elements
@@ -1263,7 +1263,7 @@ open class $ {
1263
1263
///
1264
1264
/// - parameter num: Number of times to call function
1265
1265
/// - 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 ) {
1267
1267
_ = self . times ( num) { ( index: Int ) -> ( ) in
1268
1268
function ( )
1269
1269
}
@@ -1462,29 +1462,29 @@ open class Chain<C> {
1462
1462
///
1463
1463
/// - returns: First element from the array.
1464
1464
open func first( ) -> C ? {
1465
- return $ . first( self . value)
1465
+ return `$` . first ( self . value)
1466
1466
}
1467
1467
1468
1468
/// Get the second object in the wrapper object.
1469
1469
///
1470
1470
/// - returns: Second element from the array.
1471
1471
open func second( ) -> C ? {
1472
- return $ . second( self . value)
1472
+ return `$` . second ( self . value)
1473
1473
}
1474
1474
1475
1475
/// Get the third object in the wrapper object.
1476
1476
///
1477
1477
/// - returns: Third element from the array.
1478
1478
open func third( ) -> C ? {
1479
- return $ . third( self . value)
1479
+ return `$` . third ( self . value)
1480
1480
}
1481
1481
1482
1482
/// Flattens nested array.
1483
1483
///
1484
1484
/// - returns: The wrapper object.
1485
1485
open func flatten( ) -> Chain {
1486
1486
return self . queue {
1487
- return Wrapper ( $ . flatten( $0. value) )
1487
+ return Wrapper ( `$` . flatten ( $0. value) )
1488
1488
}
1489
1489
}
1490
1490
@@ -1501,7 +1501,7 @@ open class Chain<C> {
1501
1501
/// - returns: The wrapper object.
1502
1502
open func initial( _ numElements: Int ) -> Chain {
1503
1503
return self . queue {
1504
- return Wrapper ( $ . initial( $0. value, numElements: numElements) )
1504
+ return Wrapper ( `$` . initial ( $0. value, numElements: numElements) )
1505
1505
}
1506
1506
}
1507
1507
@@ -1574,7 +1574,7 @@ open class Chain<C> {
1574
1574
/// - parameter function: Function to tell whether element value is true or false.
1575
1575
/// - returns: Whether all elements are true according to func function.
1576
1576
open func all( _ function: ( C ) -> Bool ) -> Bool {
1577
- return $ . every( self . value, callback: function)
1577
+ return `$` . every ( self . value, callback: function)
1578
1578
}
1579
1579
1580
1580
/// Returns if any element in array is true based on the passed function.
@@ -1605,7 +1605,7 @@ open class Chain<C> {
1605
1605
/// - returns: The wrapper object.
1606
1606
open func slice( _ start: Int , end: Int = 0 ) -> Chain {
1607
1607
return self . queue {
1608
- return Wrapper ( $ . slice( $0. value, start: start, end: end) )
1608
+ return Wrapper ( `$` . slice ( $0. value, start: start, end: end) )
1609
1609
}
1610
1610
}
1611
1611
0 commit comments