-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo5.js
31 lines (27 loc) · 833 Bytes
/
demo5.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
const prop = require('crocks/Maybe/prop');
const propPath = require('crocks/Maybe/propPath');
/**
* return Maybe type
*/
const getUser = id =>
new Promise((resolve, reject) => {
const result = {
status: 200,
body: {
id: 1,
username: 'tester',
email: 'test@gmail.com',
_address: {
street: '111 E. West St',
city: 'Anywhere',
state: 'PA',
postalCode: '19123-4567'
}
}
}
resolve(prop('body', result)); // return Just {}
});
const getPostalCode = propPath(['address', 'postalCode']);
getUser(1)
.then(user => user.chain(getPostalCode).option("not available"))
.then(console.log); // "19123-4567"