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的更多相关文章

  1. [Compose] 15. Applicative Functors for multiple arguments

    Working our way backwards from solution to problem, we define an applicative functor, then use it to ...

  2. [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 ...

  3. [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, ...

  4. <STL源码剖析> 6.3.6 power

    计算power的算法说明 http://www.sxt.cn/u/324/blog/2112 翻译自  http://videlalvaro.github.io/2014/03/the-power-a ...

  5. Haskell学习-functor

    原文地址:Haskell学习-functor 什么是Functor functor 就是可以执行map操作的对象,functor就像是附加了语义的表达式,可以用盒子进行比喻.functor 的定义可以 ...

  6. Function Composition vs Object Composition

    In functional programming, we create large functions by composing small functions; in object-oriente ...

  7. [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 ...

  8. 浅释Functor、Applicative与Monad

    引言 转入Scala一段时间以来,理解Functor.Applicative和Monad等概念,一直是我感到头疼的部分.虽然读过<Functors, Applicatives, And Mona ...

  9. Docker之Compose服务编排

    Compose是Docker的服务编排工具,主要用来构建基于Docker的复杂应用,Compose 通过一个配置文件来管理多个Docker容器,非常适合组合使用多个容器进行开发的场景. 说明:Comp ...

随机推荐

  1. zabbix api 设置维护模式

    通过zabbix提供的api进行维护模式的设置 #!/usr/bin/env python # -*-coding:utf-8-*- import urllib import urllib2 impo ...

  2. java学习助手

    感谢大家使用Java学习助手! 打一开始,这应用就是全开源,希望大家自觉遵循开源协议,还Android开发一片净土(国内的情况你懂的) 接下来都不会更频繁更新文章,大家更应该把注意力放在基础的模块那里 ...

  3. hdu 1069 动规 Monkey and Banana

     Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  4. Appium robotframework-appium (ios 客户端测试)环境搭建

    一. 简介 1.1摘要 本人测试新人,最近在搞ios客户端的自动化,准备采用robotframework-appium来实现自动化测试,一边学习一边总结,此安装说明文档是基于mac系统10.11版本, ...

  5. [BZOJ4553][TJOI2016&&HEOI2016]序列(CDQ分治)

    4553: [Tjoi2016&Heoi2016]序列 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1202  Solved: 554[Su ...

  6. 利用yii2分页插件,成对取出数组数据

    数组太大不好处理,切割出来处理 $ids = [1, 2, 3, 4, 5, 6, 7, 8, 9]; $count = count($ids);$size = 2; $pages = new Pag ...

  7. [转]Android适配器之ArrayAdapter、SimpleAdapter和BaseAdapter的简单用法与有用代码片段

      收藏ArrayAdapter.SimpleAdapter和BaseAdapter的一些简短代码片段,希望用时方便想起其用法. 1.ArrayAdapter 只可以简单的显示一行文本 代码片段: A ...

  8. HDU 4612 Warm up tarjan 树的直径

    Warm up 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4612 Description N planets are connected by ...

  9. mysql max_allowed_packet 设置

    mysql根据my.cnf中max_allowed_packet的大小来限制接收到的数据包大小. 据官网描述,如下图. 数据包的值范围为1k~1G, 只能是1024的倍数,不能整除1024的,会向下取 ...

  10. XPath教程

    XPath 简介 XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对元素和属性进行遍历. XPath 是 W3C XSLT 标准的主要元素,并且 XQuery ...