lodash-fp w/ user defined functions example

node v6.17.1
version: 1.0.0
endpointsharetweet
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())
Loading…

no comments

    sign in to comment