-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathchain_sample_2.ts
More file actions
45 lines (42 loc) · 1.5 KB
/
chain_sample_2.ts
File metadata and controls
45 lines (42 loc) · 1.5 KB
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
/***
* This sample demonstrates how to chain couple of async calls
* and get the final result without calling 'process()'
*/
import axios from 'axios';
import * as should from 'should';
import { Chain } from '../lib';
const api = 'http://api.mathjs.org';
async function sample2(array: number[]): Promise<number | undefined> {
return Chain(array)
.aMap(async (e) => (await axios.get(`${api}/v4/?expr=10*${e}`)).data)
.aMap(async (e) => (await axios.get(`${api}/v4/?expr=10*${e}`)).data)
.aMap(async (e) => (await axios.get(`${api}/v4/?expr=10*${e}`)).data)
.aMap(async (e) => (await axios.get(`${api}/v4/?expr=10*${e}`)).data)
.aMap(async (e) => (await axios.get(`${api}/v4/?expr=10*${e}`)).data)
.aMap(async (e) => (await axios.get(`${api}/v4/?expr=10*${e}`)).data)
.aMap(async (e) => (await axios.get(`${api}/v4/?expr=10*${e}`)).data)
.aMap(async (e) => (await axios.get(`${api}/v4/?expr=10*${e}`)).data)
.aFilter(
async (e) => (await axios.get(`${api}/v4/?expr=${e}>100000000`)).data
)
.aFilter(
async (e) => (await axios.get(`${api}/v4/?expr=${e}>200000000`)).data
)
.aFilter(
async (e) => (await axios.get(`${api}/v4/?expr=${e}>300000000`)).data
)
.aFind(
async (e) =>
(await axios.get(
`${api}/v4/?expr=${encodeURIComponent(e + '==500000000')}`
)).data
);
}
sample2([1, 2, 3, 4, 5])
.then((e) => {
// Check for value
should(e)
.Number()
.eql(500000000);
})
.catch(console.error);