Skip to content

Commit c3ea025

Browse files
committed
Refactored and remaned JavaScript examples
1 parent 598f22c commit c3ea025

File tree

11 files changed

+170
-36
lines changed

11 files changed

+170
-36
lines changed

.eslintrc.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
parserOptions:
2+
ecmaVersion: 6
3+
env:
4+
node: true
5+
extends: 'eslint:recommended'
6+
globals:
7+
api: true
8+
impress: true
9+
global: true
10+
rules:
11+
indent:
12+
- error
13+
- 2
14+
- SwitchCase: 1
15+
VariableDeclarator:
16+
var: 2
17+
let: 2
18+
const: 3
19+
MemberExpression: 1
20+
linebreak-style:
21+
- error
22+
- unix
23+
quotes:
24+
- error
25+
- single
26+
semi:
27+
- error
28+
- always
29+
eqeqeq:
30+
- error
31+
- always
32+
no-loop-func:
33+
- error
34+
strict:
35+
- error
36+
- global
37+
block-spacing:
38+
- error
39+
- always
40+
brace-style:
41+
- error
42+
- 1tbs
43+
- allowSingleLine: true
44+
camelcase:
45+
- error
46+
comma-style:
47+
- error
48+
- last
49+
comma-spacing:
50+
- error
51+
- before: false
52+
after: true
53+
eol-last:
54+
- error
55+
func-call-spacing:
56+
- error
57+
- never
58+
key-spacing:
59+
- error
60+
- beforeColon: false
61+
afterColon: true
62+
mode: minimum
63+
keyword-spacing:
64+
- error
65+
- before: true
66+
after: true
67+
overrides:
68+
function:
69+
after: false
70+
max-len:
71+
- error
72+
- code: 80
73+
ignoreUrls: true
74+
max-nested-callbacks:
75+
- error
76+
- max: 5
77+
new-cap:
78+
- error
79+
- newIsCap: true
80+
capIsNew: true
81+
properties: true
82+
new-parens:
83+
- error
84+
no-lonely-if:
85+
- error
86+
no-trailing-spaces:
87+
- error
88+
no-unneeded-ternary:
89+
- error
90+
no-whitespace-before-property:
91+
- error
92+
object-curly-spacing:
93+
- error
94+
- always
95+
operator-assignment:
96+
- error
97+
- always
98+
operator-linebreak:
99+
- error
100+
- after
101+
semi-spacing:
102+
- error
103+
- before: false
104+
after: true
105+
space-before-blocks:
106+
- error
107+
- always
108+
space-before-function-paren:
109+
- error
110+
- never
111+
space-in-parens:
112+
- error
113+
- never
114+
space-infix-ops:
115+
- error
116+
space-unary-ops:
117+
- error
118+
- words: true
119+
nonwords: false
120+
overrides:
121+
typeof: false
122+
no-unreachable:
123+
- error
124+
no-global-assign:
125+
- error
126+
no-self-compare:
127+
- error
128+
no-unmodified-loop-condition:
129+
- error
130+
no-constant-condition:
131+
- error
132+
- checkLoops: false
133+
no-console:
134+
- off
135+
no-useless-concat:
136+
- error
137+
no-useless-escape:
138+
- error
139+
no-shadow-restricted-names:
140+
- error
141+
no-use-before-define:
142+
- error
143+
- functions: false
File renamed without changes.
File renamed without changes.

JavaScript/3-functor.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function maybe(x) {
2+
return function(fn) {
3+
if (x && fn) {
4+
return maybe(fn(x));
5+
} else {
6+
return maybe(null);
7+
}
8+
};
9+
}
10+
11+
maybe(5)(x => x * 2)(console.log);
12+
maybe(null)(x => x * 2)(console.log);

JavaScript/4-functor-fp.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
global.api = {};
4+
api.fp = {};
5+
6+
api.fp.maybe = x => fn => api.fp.maybe(x && fn ? fn(x) : null);
7+
8+
api.fp.maybe(5)(x => ++x)(console.log);
9+
api.fp.maybe(5)(x => x * 2)(x => ++x)(console.log);
10+
11+
api.fp.maybe(5)(null)(console.log);
12+
api.fp.maybe(null)(x => x * 2)(console.log);
File renamed without changes.

JavaScript/maybe4.js renamed to JavaScript/6-functor-ap-fp.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,3 @@ function maybe(x) {
2020

2121
maybe(5).ap(x => ++x)(console.log);
2222
maybe(5).ap(x => x * 2).ap(x => ++x)(console.log);
23-
24-
/*
25-
let a = maybe(7);
26-
let f1 = maybe(x => x * 2);
27-
let f2 = maybe(x => ++x);
28-
a.ap(f1).ap(f2)(console.log);
29-
*/

JavaScript/path.js renamed to JavaScript/7-functor-path.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ api.fp.path(config)('server.ssl.key.filename')(
5959
api.fp.maybe(data)(console.log);
6060
})
6161
);
62+
63+
64+
api.fp.path(config).set('server.ssl.key.filename')();

JavaScript/maybe2.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

JavaScript/maybe21.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)