本文共 2408 字,大约阅读时间需要 8 分钟。
函数式编程基础
Functional programming is the process of building software by composing pure functions, avoiding shared state, mutable data, and side-effects. Functional programming is declarative (telling the computer what you want to do) rather than imperative (telling the computer exactly how to do that), and application state flows through pure functions. Contrast it with object-oriented programming, where application state is usually shared and co-located with methods in objects.
函数式编程是通过组合纯函数 ,避免共享状态 , 可变数据和副作用来构建软件的过程。 函数式编程是声明性的 (告诉计算机您想做什么),而不是命令性的 (确切地告诉计算机如何执行操作),并且应用程序状态通过纯函数流动。 与面向对象编程相反,后者通常将应用程序状态与对象中的方法共享并放置在同一位置。
Many programming languages support functional programming like Haskell, F#, Common Lisp, Clojure, Erlang, OCaml. JavaScript also has the properties of an untyped functional language.
许多编程语言都支持功能编程,例如Haskell,F#,Common Lisp,Clojure,Erlang,OCaml。 JavaScript还具有非类型化功能语言的属性。
Functional programming has long been popular in academia, but with few industrial applications. However, recently several prominent functional programming languages have been used in commercial or industrial systems. For example, the Erlang programming language, which was developed by the Swedish company Ericsson in the late 1980s, is used for building a range of applications at companies such as T-Mobile, Nortel, Facebook, Électricité de France and WhatsApp.
函数式编程在学术界很久以来一直很流行,但是很少有工业应用。 但是,最近在商业或工业系统中使用了几种著名的功能编程语言。 例如,由瑞典爱立信公司在1980年代后期开发的Erlang编程语言用于在T-Mobile,Nortel,Facebook,Électricitéde France和WhatsApp等公司构建一系列应用程序。
Higher-order functions are a big part of functional programming. A higher-order function is a function that either takes a function(s) as a parameter or returns a function.
高阶函数是函数编程的重要组成部分。 高阶函数是将一个或多个函数作为参数或返回一个函数的函数。
map
is a higher-order function that calls a function to each element of a list, and returns the results as a new list.
map
是一个高阶函数,它调用一个函数到列表的每个元素,并将结果作为新列表返回。
Here is an example of map
:
这是map
的示例:
const myList = [6, 3, 5, 29];let squares = myList.map(num => num * num); // [36, 9, 25, 841]
翻译自:
函数式编程基础
转载地址:http://jxzzd.baihongyu.com/