functional-switchcase
Version:
Functional switchcase taken from a Hackernoon article by Joel Thoms
14 lines (10 loc) • 332 B
JavaScript
const executeIfFunction = f =>
typeof f === 'function' ? f() : f
const switchcase = cases => defaultCase => key =>
cases.hasOwnProperty(key) ? cases[key] : defaultCase
const switchcaseF = cases => defaultCase => key =>
executeIfFunction(switchcase(cases)(defaultCase)(key))
module.exports = {
switchcase,
switchcaseF
}