全部书籍

专业

应用 关于 Coach 登录 开始阅读

书籍暂未推出简体中文版——当前显示英文版。

Computer Science · 术语表

什么是 Map operation, filter, fold?

又称: map operation · filter · fold

Definition 9.3 University Computer Science — Year 2 · 第 9 章 — Functional Programming

On a sequence [x1,…,xn][x_1, \dots, x_n], the map operation with a function ff gives [f(x1),…,f(xn)][f(x_1), \dots, f(x_n)]; the filter with a predicate pp keeps the xix_i with p(xi)p(x_i) true, in order; the fold from zz with a two-argument function gg gives g(…g(g(z,x1),x2)…,xn)g(\dots g(g(z, x_1), x_2) \dots, x_n) (a left fold; the right fold is g(x1,g(x2,…g(xn,z)))g(x_1, g(x_2, \dots g(x_n, z)))). Sums, counts, maxima, and the building of collections are folds.

在原文中阅读 →