Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/basementuniverse/async
- Owner: basementuniverse
- License: mit
- Created: 2022-04-13T16:56:24.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-04-13T17:38:44.000Z (over 2 years ago)
- Last Synced: 2024-12-05T00:17:39.450Z (about 1 month ago)
- Language: TypeScript
- Size: 73.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
*/
```