本文的主要内容来自<Functional Programming in Swift>这本书,有点所谓的观后总结 在本书的Introduction章中: we will try to focus on some of the qualities that we believe well-designed functional programs in Swift should exhibit: 1. Modulatity[模块化] 2. A Careful Treatment of Mutable…
这节开始讲的例子都使用简单的TS来写,尽量做到和es6差别不大,正文如下 我们在编程中必然需要用到一些变量存储数据,供今后其他地方调用.而函数式编程有一个要领就是最好不要依赖外部变量(当然允许通过参数传递咯),如何解决这个矛盾的问题呢?将函数柯里化`Curry`就可以了,这种技巧可以让函数记住一些历史数据,也就是缓存,怎么做呢? 说柯里化之前必须先说一下闭包,因为这是实现柯里化的方法. 闭包 const fun = () => { let a = 0; return () => { a +=…