惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
V
V2EX
aimingoo的专栏
aimingoo的专栏
爱范儿
爱范儿
博客园 - 聂微东
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
月光博客
月光博客
云风的 BLOG
云风的 BLOG

博客园 - 坚强2002

[Erlang 0129] Erlang 杂记 VI Graphviz绘制百家争鸣图 [Erlang 0128] Term sharing in Erlang/OTP 下篇 [Erlang 0127] Term sharing in Erlang/OTP 上篇 Elixir 1.0 Release [Erlang 0126] 我们读过的Erlang论文 读几首诗 [Erlang 0125] Know a little Erlang opcode [Erlang 0124] Erlang Unicode 两三事 - 补遗 [Erlang 0123] Erlang EPMD [Erlang 0122] Erlang Resources 2014年1月~6月资讯合集 [Erlang 0121] 当我们谈论Erlang Maps时,我们谈论什么 Part 3 [Erlang 0120] Know a little Core Erlang [Erlang 0119] Erlang OTP 源码阅读指引 [Erlang 0118] Erlang 杂记 V [Erlang 0117] 当我们谈论Erlang Maps时,我们谈论什么 Part 2 [Erlang 0116] 当我们谈论Erlang Maps时,我们谈论什么 Part 1 致鸡鸣狗盗 一个技术人的知识管理方法论
"Becoming Functional" 阅读笔记+思维导图
坚强2002 · 2014-08-06 · via 博客园 - 坚强2002

 

  <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.