I am trying to make a curry function like in Lodash http://lodash.com/docs#curry
Unfortunately I am getting two compile errors.
func curry(fun: (Any...)) -> ((Any...) -> (Any)) {
let count = fun.0.count
var resultArgs: Any[] = []
func generator(newArgs: Any...) -> ((Any...) -> (Any))? {
for (index, elem) in enumerate(newArgs) {
if resultArgs.count >= count {
break
} else {
resultArgs += elem
}
}
if resultArgs.count >= count {
// fun(resultArgs)
// Commenting fun now cause that throws a compile error saying array cannot be passed in Variadic parameter function
return nil
} else {
return generator
}
}
return generator
}
There are two issues here:
- Segmentation faults for some reason on the generator function. Idea behind this function is to take parameters and return a new function or not return nothing at all and evaluate the function
funpassed in the curry function - Passing array of arguments to a function that accepts Variadic parameters. This should be a given in a language as we can do this using the
performSelectorin Objective-C
How can I solve these two problems?
I am getting the following error for the generator function which is a segmentation fault during compile time
1. While emitting IR SIL function @_TTRXFt_oGSaP__oBolGSaP__dSioXFo_oGSaP___oGSqFtGSaP___P____oGSqFtGSaP___P___XFo_oGSaP___oGSqFtGSaP___P___ for 'generator'
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254
func foo() { func bar() { bar() } }