-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathchain_sample_1.ts
More file actions
49 lines (45 loc) · 1.59 KB
/
chain_sample_1.ts
File metadata and controls
49 lines (45 loc) · 1.59 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
46
47
48
49
/***
* This sample demonstrates how to chain couple of async calls
* and get the final result buy calling 'process()'
*/
import axios from 'axios';
import * as should from 'should';
import { Chain } from '../lib';
import { AsyncArray } from '../lib/async_array';
const api = 'http://api.mathjs.org';
async function sample1(array: number[]): Promise<number[]> {
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
)
.aFilter(
async (e) => (await axios.get(`${api}/v4/?expr=${e}>400000000`)).data
)
.process();
}
sample1([1, 2, 3, 4, 5])
.then((e) => {
// Check for instance type
should(e)
.instanceOf(AsyncArray)
.and.size(1);
// Check for value
should(e[0])
.Number()
.eql(500000000);
})
.catch(console.error);