Sakai-san / functional-programming-by-doing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Functional programming concepts in 50 lines of code

Introduction

I contrast to a rather theoretical post I wrote previously on medium on functional programming, the present post is more pragmatic. Based on a very little project basic principles of functional programming are exposed.

Functional programming

A functional programming progamm made of functions.

Callback

Function passed to another function and called within the hosted function.

Recursion

Do not mutate data. Do write tail recursive function.

Closure

Parameterized a function. Function expecting a specfic signature.

Decorator

Parameterized a function. Function expecting a specfic signature.

Hight order function

Expect function (callback) or returs a function.

Isolate side effect

Programms without side-effect are very restrictive.

Benefit of using functional programming

Less code, easier to read, easier to test.

JavaScript and functional programming

Functional programming is a style. Functional programming principle can be implemented in any language. Of course some languages are more adjusted for that. JavaScript by supporting cloure and function as first class citizen is quite adaquated for functional programming. But JavaScript does not support immutability by default.

About


Languages

Language:HTML 77.7%Language:JavaScript 22.3%