【发布时间】:2015-04-12 13:01:51
【问题描述】:
这是官方文档所说的
updateIn(keyPath: Array<any>, updater: (value: any) => any): List<T>
updateIn(keyPath: Array<any>, notSetValue: any, updater: (value: any) => any): List<T>
updateIn(keyPath: Iterable<any, any>, updater: (value: any) => any): List<T>
updateIn(keyPath: Iterable<any, any>, notSetValue: any, updater: (value: any) => any): List<T>
普通的 Web 开发人员(不是函数式程序员)无法理解这一点!
我有一个非常简单的(用于非功能性方法)案例。
var arr = [];
arr.push({id: 1, name: "first", count: 2});
arr.push({id: 2, name: "second", count: 1});
arr.push({id: 3, name: "third", count: 2});
arr.push({id: 4, name: "fourth", count: 1});
var list = Immutable.List.of(arr);
如何更新list,其中名称为 third 的元素的 count 设置为 4?
【问题讨论】:
-
我不知道它长什么样,但是文档很糟糕facebook.github.io/immutable-js/docs/#/List/update
-
严重赞成对文档的挖掘。如果该语法的目标是让我感到愚蠢/不足,那么肯定是成功的。但是,如果目标是传达 Immutable 的工作原理,那么……
-
我必须同意,我发现 immutable.js 的文档非常令人沮丧。公认的解决方案使用我在文档中根本没有看到的方法 findIndex()。
-
我宁愿他们给每个函数一个例子而不是那些东西。
-
同意。文档一定是由某个科学家在泡沫中编写的,而不是由想要展示一些简单示例的人编写的。文档需要一些文档。例如,我喜欢下划线的文档,更容易看到实际示例。
标签: javascript functional-programming immutable.js