"Becoming Functional" 阅读笔记+思维导图-阿里云开发者社区

开发者社区> 唐玄奘> 正文

"Becoming Functional" 阅读笔记+思维导图

简介:
+关注继续查看

 

  <Becoming Functional>是O'Reilly公司今年(2014)7月发布的一本薄薄的小册子,151页,介绍了函数式编程的基本概念.全书使用代码范例都是基于JVM的编程语言,比如Java,Groovy,Scala.为了能够讲解所有的知识点,作者不得不在多个语言之间做切换,其实使用Erlang,Elixir甚至是C#做范例都不会这么累(因为C#有Linq,Lazy.....).

 
   这本书侧重点是讲解基本概念,以及思维方式的转变.所以无论是搞哪一种函数式编程语言,都可以读一读,一开始接触Erlang的小伙伴问的最多的就是:Tail Recursion,Side Effects,Higher-Order Functions,Anonymous Functions,closures,这里恰好有一个不太复杂的讲解.
 
    这本书作为一个入门的小册子,内容足够简单,可以快速翻完,下面是我阅读该书的时候做下的思维导图及其文字版.

 

 

 

附文字版

 

Becoming Functional

First-class functions

can either accept another function as an argument or return a function.

 Pure functions

are functions that have no side effects. Side effects are actions a function may perform that are not solely contained within the function itself.

Side Effects

 Recursion

allows us to write smaller, more concise algorithms and to operate by looking only at the inputs to our functions.

Tail Recursion

 Immutable variables

Immutable variables, once set, cannot be changed.

Nonstrict (Lazy) evaluation

 allow us to have variables that have not been computed yet.

Strict evaluations-assigning a variable as soon as it is defined-are what we are used to

Nonstrict means that we can have a variable that does not get assigned (computed) until the first time it is referenced.

 Statements

are evaluable pieces of code that have a return value. 

Each line of code should be considered a statement, meaning there are very few side effects within the application itself.

Pattern matching

allows us to better type-check and extract elements from an object, making for simpler and more concise statements with less need for variable definitions.

extracting value

First-class functions

Anonymous Functions

closures

Closures are much like lambdas, except they reference variables outside the scope of the function.

In the simplest explanation, the body references a variable that doesn't  exist in either the body or the parameter list.

lambda functions

Lambda functions are unnamed functions that contain a parameter list, a body, and a return.

Higher-Order Functions

A function becomes "higher order" if it accepts or returns a function.

 Pure functions

Output Depends on Input

When we don't return the result of our execution but rather mutate another external (i.e., not contained within the function scope) object, we call this a side effect.

 Pure functions are functions that have no side effects and always perform the same computation,resulting in the same output, given a set of inputs.

Really, you want to make a function pure whenever possible; it makes the function much more testable and improves understandability from a troubleshooting perspective.


本文转自博客园坚强2002的博客,原文链接:

http://www.cnblogs.com/me-sa/p/becoming_functional.html

如需转载请自行联系原博主。


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Effctive_java_01 阅读笔记
使用静态工厂方法替代构造方法,静态工厂方法的优劣势
4024 0
思维导图概览SpringCloud
思维导图概览SpringCloud
12 0
《JavaScript高级程序设计(第3版)》阅读笔记
第6章 面向对象的程序设计 6.2 创建对象 6.2.1 工厂模式 JavaScript创建对象(一)—— 工厂模式 6.
833 0
+关注
641
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载