-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (38 loc) · 1.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {
sum,
mapNewProperty,
curriedMapNewProperty,
filterFromArray,
} from './currying/index';
import { promiseObject } from './promises/index';
import {
gamesList,
filterList
} from './mock-data/arrayObjects';
const even = (num) => num%2 ===0;
const odd = (num) => num%2 !== 0;
/**
* simple curry function usage example
*/
console.log(sum(20)); //will not execute but will return the last function without executing
console.log(sum(20)(10)); //will return 30
console.log(sum(20)()); //will return NaN since the last parameter is undefined
/**
* mapNewProperty is not curried which makes it a tightly coupled function
*/
console.log('games with new property', gamesList.map( mapNewProperty ));
console.log('curried function returning new property', curriedMapNewProperty(gamesList)({ psnExclusive: true }));
console.log('some more example', curriedMapNewProperty(gamesList)({}));
/**ToDO: add examples with Rambda
*/
console.log('filter curried', filterFromArray(filterList)(even));
console.log('filter curried', filterFromArray(filterList)(odd));
const requestData = {
psnExclusive: true
};
const badRequestData = {
psnExclusive: false
};
promiseObject(requestData)
.then(gameObject=> console.log('inside then', gameObject))
.catch(errorMessage => console.log('Error caught inside catch',errorMessage));