[Functional Programming] Function modelling -- 4. Reader Monda example
-- Function Programming Example functional Reader
2023-09-14 09:00:47 时间
const Reader = run => ({ run, map: f => Reader(x => f(run(x))), chain: f => Reader(x => f(run(x)).run(x)), concat(o) { return Reader(x => run(x).concat(o.run(x))); } }); Reader.of = x => Reader(() => x); Reader.ask = Reader(x => x); const prefix = s => m => `${s}${m}`; const prefixHttps = prefix("https://"); const prefixHttp = prefix("http://"); const res = Reader.of("localhost") .chain(host => Reader.ask.map(config => config.https ? prefixHttps(host) : prefixHttp(host) ) ) .chain(domain => Reader.ask.map(config => `${domain.concat(":").concat(config.port)}`) ) .run({ port: 3000, https: true }); console.log(res); // https://localhost:3000
相关文章
- Spring MVC更多家族成员--国际化视图与LocalResolver---10
- 低功耗设计方法--低功耗IP设计(一)
- SQLite数据库教程--Keep Learning系列
- 执行计划--mysql详解(七)
- Undo日志--mysql详解(十)
- ps2019最新下载地址+安装教程图解--所有PS版本都有!
- 辗转相除法--最大公约数
- C语言小项目 -- 五子棋小游戏(通用版)
- 【错误记录】Ubuntu 编译 ffmpeg 报错 ( nasm/yasm not found or too old. Use --disable-x86asm for a crippled bu )
- RFC_GET_FUNCTION_INTERFACE_P获取函数(function module)参数详解编程语言
- 兼容ie和firefox的鼠标经过(onmouseover和onmouseout)实现--简短版
- jQuery学习笔记(2)--用jquery实现各种模态提示框代码及项目构架
- 与MSSQL对比学习MYSQL的心得(四)--BLOB数据类型