function eq (y) {
return function forX(x) {
return x === y
}
}
function mod (y) {
return function forX (x) {
return x % y
}
}
function compose (fn2, fn1) {
return function composed (val) {
return fn2(fn1(val))
}
}
function not (fn) {
return function negated (...args) {
return !fn(...args)
}
}
isOdd = compose(
eq(1),
mod(2)
)
isEven = not(isOdd)
let fiveIsOdd = isOdd(5)
let fourIsEven = isEven(4)
console.log(`5 is odd ${fiveIsOdd}`)
console.log('4 is even', fourIsEven)
javascript fp demo
推荐阅读
- solc@0.6.3 web3@1.2.6 都是最新版本的,编译与部署示例
- Jupyter Notebook:FileNotFoundError: [WinError 2] 系统找不到指定的文件
- Jupyter notebook配置问题 - 添加多个kernels
- Ubuntu16.04 使用随笔 - ”.bin“、”.tar.gz“、”.tar.bz2“格式的软件包
- 在Ubuntu16.04上使用anaconda3安装GPU版本的tensorflow (DELL Vostro 7580)
- SpringBoot配置RedisTemplate
- PL/SQL数据类型
- SpringBoot Swagger3.0配置
- PL/SQL控制语句(二、循环控制语句)
- PL/SQL变量和类型