[Compose] 17. List comprehensions with Applicative Functors
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" ]
[Compose] 17. List comprehensions with Applicative Functors的更多相关文章
- [Compose] 15. Applicative Functors for multiple arguments
Working our way backwards from solution to problem, we define an applicative functor, then use it to ...
- [Functional Programming] Working with two functors(Applicative Functors)-- Part1 --.ap
What is applicative functor: the ability to apply functors to each other. For example we have tow fu ...
- [Functional Programming] Working with two functors(Applicative Functors)-- Part2 --liftAN
Let's examine a pointfree way to write these applicative calls. Since we know map is equal to of/ap, ...
- <STL源码剖析> 6.3.6 power
计算power的算法说明 http://www.sxt.cn/u/324/blog/2112 翻译自 http://videlalvaro.github.io/2014/03/the-power-a ...
- Haskell学习-functor
原文地址:Haskell学习-functor 什么是Functor functor 就是可以执行map操作的对象,functor就像是附加了语义的表达式,可以用盒子进行比喻.functor 的定义可以 ...
- Function Composition vs Object Composition
In functional programming, we create large functions by composing small functions; in object-oriente ...
- [Compose] 16. Apply multiple functors as arguments to a function (Applicatives)
We find a couple of DOM nodes that may or may not exist and run a calculation on the page height usi ...
- 浅释Functor、Applicative与Monad
引言 转入Scala一段时间以来,理解Functor.Applicative和Monad等概念,一直是我感到头疼的部分.虽然读过<Functors, Applicatives, And Mona ...
- Docker之Compose服务编排
Compose是Docker的服务编排工具,主要用来构建基于Docker的复杂应用,Compose 通过一个配置文件来管理多个Docker容器,非常适合组合使用多个容器进行开发的场景. 说明:Comp ...
随机推荐
- Python函数系列-一个简单的生成器的例子
def consumer(): while True: x = yield print('处理了数据:',x) def producer(): pass c = consumer() #构建一个生成器 ...
- MySQL 5.7 安装完成后,首次登陆的几个问题
Server:CentOS 7.0 MySQL : 5.7.20 MySQL Community Server (GPL) 1.首次登陆后修改密码: 根据安装时的选择不同,有mysqld_safe用m ...
- HDU 1325(并查集)
Is It A Tree? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- FFTW3学习笔记3:FFTW 和 CUFFT 的使用对比
一.流程 1.使用cufftHandle创建句柄 2.使用cufftPlan1d(),cufftPlan3d(),cufftPlan3d(),cufftPlanMany()对句柄进行配置,主要是配置句 ...
- 是否排序好了 Exercise07_19
import java.util.Scanner; import java.util.Arrays; /** * @author 冰樱梦 * 时间2018年12月 * 题目:是否排序好了 * */ p ...
- Markdown---锚点使用
Markdown目前还没有支持文内锚点的标记语法:但是支持html,所以锚点可以通过html语法来实现 使用方法 <a href='#jump'>第一个题目</a> 带有锚点的 ...
- 配置Maven环境变量与Intelij IDE配置Maven
Maven有什么用? 以前我们导入第三方jar包的流程是什么?一般是download,然后copy到项目中,然后依赖(library)项目,最后被我们使用. 通俗的说,就是不用我们自己去downloa ...
- python中获取当前位置所在的行号和函数名(转)
http://www.vimer.cn/2010/12/%E5%9C%A8python%E4%B8%AD%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E4%BD%8D%E7 ...
- 01-03-01【Nhibernate (版本3.3.1.4000) 出入江湖】id标签的unsaved-value属性
父表 <class name="Model.Customer, Model" discriminator-value="0"> <!--uns ...
- Eclipse 中导入jar包
导入到工程即可使用了1. 在程序目录下,创建一个文件夹,如 lib. 2. 将第三方jar包复制到该目录下3.右键工程,选择Build path4.java build path,选择 librari ...