File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,37 @@ A Cookbook for writing FP in JavaScript using ES6
3
3
4
4
### Summary
5
5
6
+ * [ Pure functions] ( #pure-functions )
6
7
* [ Higher-order functions] ( #higher-order-functions )
7
8
* [ Recursion] ( #recursion )
8
9
* [ Functor] ( #functor )
9
10
* [ Destructuring] ( #destructuring )
10
11
* [ Currying] ( #currying )
11
12
13
+ ### Pure functions
14
+ Returns the same result given same parameters. It's execution doesn't depend on the state of the system
15
+
16
+ 1 ) Impure
17
+
18
+ ``` javascript
19
+ let number = 1 ;
20
+ let increment = () => {
21
+ return number += 1 ;
22
+ };
23
+ increment ();
24
+ // 2
25
+ ```
26
+
27
+ 2 ) Pure
28
+
29
+ ``` javascript
30
+ let increment = (n ) => {
31
+ return n + 1 ;
32
+ };
33
+ increment (1 );
34
+ // 2
35
+ ```
36
+
12
37
### Higher-order functions
13
38
Functions that operate on other functions, either by taking them as arguments or by returning them
14
39
@@ -213,3 +238,7 @@ addFive(10);
213
238
[ https://www.youtube.com/playlist?list=PL0zVEGEvSaeEd9hlmCXrk5yUyqUag-n84 ] ( https://www.youtube.com/playlist?list=PL0zVEGEvSaeEd9hlmCXrk5yUyqUag-n84 )
214
239
215
240
[ http://functionaljavascript.blogspot.com.br/2013/07/functors.html ] ( http://functionaljavascript.blogspot.com.br/2013/07/functors.html )
241
+
242
+ [ http://nicoespeon.com/en/2015/01/pure-functions-javascript/ ] ( http://nicoespeon.com/en/2015/01/pure-functions-javascript/ )
243
+
244
+ [ https://drboolean.gitbooks.io/mostly-adequate-guide/ ] ( https://drboolean.gitbooks.io/mostly-adequate-guide/ )
Original file line number Diff line number Diff line change
1
+ // pure fuctions
2
+ var number = 1 ;
3
+ var increment = function ( ) {
4
+ return number += 1 ;
5
+ } ;
6
+ console . log ( increment ( ) ) ;
7
+
8
+ var increment = function ( n ) {
9
+ return n + 1 ;
10
+ } ;
11
+ console . log ( increment ( 1 ) ) ;
12
+
1
13
// Sum
2
14
let sum = ( x , y ) => {
3
15
return x + y ;
You can’t perform that action at this time.
0 commit comments