This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func addTwo(_ num: Int) -> Int { | |
return num + 2 | |
} | |
addTwo(2) // 4 | |
addTwo(3) // 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func partialAdd(_ fixed: Int) -> (Int)->Int { | |
return { (num) -> Int in num + fixed} | |
} | |
let addTwo = partialAdd(2) | |
let addThree = partialAdd(3) | |
let addALot = partialAdd(284) | |
addTwo(3) // 5 | |
addThree(5) // 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addTwo(addThree(addTwo(1))) //8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func pipe(_ fns: (Int) -> (Int)...) -> (Int) -> (Int) { | |
return { (input) in fns.reduce(input, {value, fn in fn(value)})} | |
} | |
pipe(addOne, addOne)(1) // 3 | |
pipe(addOne, addTwo, addOne)(1) // 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func pipe<T>(_ fns: (T) -> (T)...) -> (T) -> (T) { | |
return { (input) in fns.reduce(input, {value, fn in fn(value)})} | |
} | |
func addPrefix(_ prefix: String) -> (String) -> (String) { | |
return {(inputStr) in "\(prefix) \(inputStr)" } | |
} | |
func addSuffix(_ suffix: String) -> (String) -> (String) { | |
return {(inputStr) in "\(inputStr), \(suffix)" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipe( | |
getToken, | |
makeRequest, | |
mapResponse, | |
sendReactiveSignal | |
)(requestObject) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
replaceParams, | |
composeURL, | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const template = 'api/{id}/{action}' | |
const params = {id: 123, action: 'run'} | |
const endpoint = replaceParams(template, params) // api/123/run | |
const host = process.env.HOST | |
const uri = composeUrl(host, endpoint) // http://api.name.com/api/123/run | |
const requestOptions = { uri } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
method1, | |
method2, | |
... | |
} | |
function method1 () {} | |
function method2 () {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pipe :: [any -> any] -> any -> any | |
pipe( | |
executeFirst, | |
executeSecond | |
)(initialValue) |