函数式编程基础_函数式编程基础知识

函数式编程基础

功能编程 (Functional Programming)

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.

函数式编程是通过组合纯函数 ,避免共享状态可变数据副作用来构建软件的过程。 函数式编程是声明性的 (告诉计算机您想做什么),而不是命令性的 (确切地告诉计算机如何执行操作),并且应用程序状态通过纯函数流动。 与面向对象编程相反,后者通常将应用程序状态与对象中的方法共享并放置在同一位置。

为什么要进行函数式编程? (Why Functional Programming?)

  • It’s generally more concise

    通常更简洁
  • It’s generally more predictable

    通常更可预测
  • It’s easier to test than object-oriented code

    比面向对象的代码更容易测试

通过编程语言采用 (Adoption by Programing Languages)

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还具有非类型化功能语言的属性。

用途 (Uses)

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)

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)

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]

有关函数式编程的更多信息: (More Information on Functional Programming:)

翻译自: https://www.freecodecamp.org/news/intro-to-functional-programming-basics/

函数式编程基础

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值