[Compose] 17. List comprehensions with Applicative Functors
2024-08-28 23:26:17
We annihilate the need for the ol' nested for
loop using Applicatives.
For example we have this kind of nested loop code:
for(x in xs){
for(x in ys){
for(z in zs){ }
}
}
We can refactor it by using List comprehension:
const {List} = Immutable;
const res1 = List.of(x => x).ap(List([,,]));
console.log(res1) // List [ 1,2,3 ]
const res1 = List.of(x => y=> `${x} - ${y}`)
.ap(List(['teeshirt', 'sweater']))
.ap(List(['large', 'medium', 'small']));
console.log(res1) //List [ "teeshirt - large", "teeshirt - medium", "teeshirt - small", "sweater - large", "sweater - medium", "sweater - small" ]
最新文章
- testng 6.8.6 eclipse plugin
- vim插件ctags的安装和使用
- MVC – 5.MVC设计模式和.NetMVC框架
- Java序列化中的serialVersionUID有什么用?
- String equals的技巧
- 【形式化方法:VDM++系列】2.VDMTools环境的搭建
- Mysql engine
- linux 双网关双IP设置
- Python 基础 字符串拼接 + if while for循环
- 文件上传下载样式 --- bootstrap
- 意外发现的大批量导入数据SqlBulkCopy类
- mybatis mapper.xml 写关联查询 运用 resultmap 结果集中 用 association 关联其他表 并且 用 association 的 select 查询值 报错 java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mybatis.map
- Java---SSH(MVC)面试题
- 排序算法(sorting)
- [Linux] Linux Shell查找文件
- Cookie/Session机制详解(转载)
- [osg]osg背景图设置
- C++ 的那些坑 (Day 2)
- DevOps之技能面
- HiveSql调优经验