Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/basementuniverse/async

Async versions of common list functions
https://github.com/basementuniverse/async

Last synced: 23 days ago
JSON representation

Async versions of common list functions

Awesome Lists containing this project

README

        

# Async

Async versions of common list functions.

## Installation

```
npm install @basementuniverse/async
```

## Usage

See [docs](docs/modules.md) for more information.

### asyncForEach

```typescript
import { asyncForEach } from '@basementuniverse/async';

await asyncForEach(
[
'one',
'two',
'three',
],
async (value: string) => {
await fetch(`localhost:8080/${value}`);
}
);
```

---

### asyncMap

```typescript
import { asyncMap } from '@basementuniverse/async';

const results = await asyncMap(
[
'123',
'456',
'789',
],
async (value: string) => {
// asynchronous stuff here...
return Number(value);
}
);

/*
results: [123, 456, 789]

Note that the order of results might be different.
*/

```

---

### asyncFilter

```typescript
import { asyncFilter } from '@basementuniverse/async';

const results = await asyncFilter(
[
'allowed1',
'notAllowed2',
'allowed3',
'notAllowed4',
],
async (value: string) => {
// asynchronous stuff here...
return value.startsWith('allowed');
}
);

/*
results: ['allowed1', 'allowed2']

Note that the order of results might be different.
*/
```

---

### asyncReduce

```typescript
import { asyncReduce } from '@basementuniverse/async';

const result = await asyncReduce(
[
'1',
'2',
'3',
],
async (previous: number, current: string) => {
// asynchronous stuff here...
return previous + Number(current);
},
0
);

/*
result: 6
*/
```