Skip to content

Commit c994645

Browse files
committed
Added namespaces to JavaScript examples
1 parent 6f8b215 commit c994645

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

JavaScript/6-functor-ap-fp.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
'use strict';
22

3-
const mapNull = (fn, x) => x ? fn(x) : null;
3+
global.api = {};
44

5-
function maybe(x) {
6-
const map = fn => maybe(mapNull(fn, x));
7-
map.ap = fnA => fnA(fn => mapNull(fn, x));
5+
api.fp = {};
6+
7+
api.fp.mapNull = (fn, x) => x ? fn(x) : null;
8+
9+
api.fp.maybe = x => {
10+
const map = fn => api.fp.maybe(api.fp.mapNull(fn, x));
11+
map.ap = fnA => fnA(fn => api.fp.mapNull(fn, x));
812
map.chain = fnM => fnM(x);
913
return map;
1014
}
1115

12-
maybe(5)(x => x * 2)(x => ++x)(console.log);
13-
maybe(5)(x => x * 2).ap(maybe(x => ++x))(console.log);
14-
maybe(5).chain(x => maybe(x * 2))(x => ++x)(console.log);
16+
api.fp.maybe(5)(x => x * 2)(x => ++x)(console.log);
17+
api.fp.maybe(5)(x => x * 2).ap(api.fp.maybe(x => ++x))(console.log);
18+
api.fp.maybe(5).chain(x => api.fp.maybe(x * 2))(x => ++x)(console.log);
1519

1620
const config = {
1721
coords: {
@@ -30,6 +34,6 @@ const addVelocity = velocity => coords => {
3034
return coords;
3135
};
3236

33-
const coords = maybe(config.coords);
34-
const velocity = maybe(config.velocity);
37+
const coords = api.fp.maybe(config.coords);
38+
const velocity = api.fp.maybe(config.velocity);
3539
coords.ap(velocity(addVelocity))(console.log);

JavaScript/7-functor-path.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ api.fp.maybe = x => fn => api.fp.maybe(x && fn ? fn(x) : null);
2121

2222
const fs = require('fs');
2323

24-
let config = {
24+
const config = {
2525
server: {
2626
host: {
2727
ip: '10.0.0.1',
2828
port: 3000
2929
},
3030
ssl: {
3131
key: {
32-
filename: './path.js'
32+
filename: './7-functor-path.js'
3333
}
3434
}
3535
}
@@ -59,6 +59,3 @@ 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')();

0 commit comments

Comments
 (0)