Lift your function into maybe
Clean up your code by ensuring that function arguments will never be undefined
// Turn this:
function toUpper(string) {
if (string === undefined) {
return undefined
}
return string.toUpperCase()
}
// Into this:
const toUpper = maybe(string => string.toUpperCase())
npm install function-maybe
import maybe from 'function-maybe'
const toUpper = maybe(string => string.toUpperCase())
console.log(toUpper('doge')) // => DOGE
console.log(toUpper(undefined)) // => undefined
const join = separator => maybe(list => list.join(separator))
const format = pipe(join(','), toUpper)
console.log(format(['doge', 'such', 'wow!'])) // => DOGE,SUCH,WOW!
console.log(format(undefined)) // => undefined
npm test