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: ,,])); console.log(res1) // List…
Working our way backwards from solution to problem, we define an applicative functor, then use it to apply a function of multiple arguments. For example we have this line of code: ).ap(Box())// Box(3); We want to use a funciton 'ap' (apply) on Box. A…
What is applicative functor: the ability to apply functors to each other. For example we have tow functors: Container(2), Container(3) // We can't do this because the numbers are bottled up. add(Container.of(), Container.of()); // NaN We cannot just…
Let's examine a pointfree way to write these applicative calls. Since we know map is equal to of/ap, we can write generic functions that will ap as many times as we specify: const liftA2 = curry((g, f1, f2) => f1.map(g).ap(f2)); const liftA3 = curry(…
计算power的算法说明 http://www.sxt.cn/u/324/blog/2112 翻译自  http://videlalvaro.github.io/2014/03/the-power-algorithm.html 1.快速求幂算法 在这篇文章我会展示怎样通过求一个数的幂的基本思路,来引导我们发现一些抽象的东西比如半群和含幺半群. 有一个很有名的对一个数求幂的算法,也就是说,求一个数x的n次方或者这样简单表示:x^n.Donald Knuth在TAOCP的4.63节 求幂值中提出这个…
原文地址:Haskell学习-functor 什么是Functor functor 就是可以执行map操作的对象,functor就像是附加了语义的表达式,可以用盒子进行比喻.functor 的定义可以这样理解:给出a映射到b的函数和装了a的盒子,结果会返回装了b的盒子.fmap 可以看作是一个接受一个function 和一个 functor 的函数,它把function 应用到 functor 的每一个元素(映射). -- Functor的定义 class Functor f where fma…
In functional programming, we create large functions by composing small functions; in object-oriented programming, we create large objects by composing small objects. They are different types of composition. They might sound similar, but there is som…
We find a couple of DOM nodes that may or may not exist and run a calculation on the page height using applicatives. For example we want to get the main content section size by reduce the height of header and footer, nomarlly we will do like this: 1.…
引言 转入Scala一段时间以来,理解Functor.Applicative和Monad等概念,一直是我感到头疼的部分.虽然读过<Functors, Applicatives, And Monads In Pictures> 一文,但深感未得甚解,仍是翻书了然.关书茫然. 于是转而"曲线救国"--选择学习更加纯粹的FP语言Haskell,尝试结合着对范畴论的一点粗鄙理解,再从Haskell与Scala不同编码实现的角度去比较,结果真有柳暗花明又一村的感觉.参考书籍为著名的&…
Compose是Docker的服务编排工具,主要用来构建基于Docker的复杂应用,Compose 通过一个配置文件来管理多个Docker容器,非常适合组合使用多个容器进行开发的场景. 说明:Compose是Fig的升级版,Fig已经不再维护.Compose向下兼容Fig,所有fig.yml只需要更名为docker-compose.yml即可被Compose使用. 服务编排工具使得Docker应用管理更为方便快捷. Compose网站:https://docs.docker.com/compos…