lodash-fp w/ user defined functions example
const compose = require('lodash/fp/compose');
const curry = require('lodash/fp/curry');
const toUpper = curry(input => {
return input.toUpperCase()
})
//This returns a function, which is correct because it's a curried function and it's arity has not been satisfied
console.log(toUpper())
//This returns what I expect, which is "HELLO WORLD"
console.log(toUpper("hello world"))
const reverseString = curry(input => {
return input.split("").reverse().join("")
})
//"olleh" looks right to me!
console.log(reverseString("hello"))
//Let's try putting it all together with function composition
const uppercaseAndReverse = compose(reverseString, toUpper)
//"OLLEH" is exactly what I expected
console.log(uppercaseAndReverse("hello"))
//ERROR: input.split is not a function
console.log(uppercaseAndReverse())
no comments