Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/littlstar/gean
"Composable" Generator Control
https://github.com/littlstar/gean
Last synced: about 2 months ago
JSON representation
"Composable" Generator Control
- Host: GitHub
- URL: https://github.com/littlstar/gean
- Owner: littlstar
- License: mit
- Created: 2015-10-26T20:43:50.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-09T19:26:09.000Z (about 9 years ago)
- Last Synced: 2024-11-10T02:34:31.016Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 15
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
gean
====gean provides a mechanism for composable generator control with
promises.## why ?
* tiny.
* zero dependencies.
* composable.
* `Promise` based.## installation
```sh
$ npm install gean --save
```## usage
```js
gean(function * () {
// flow control here
});
````gean` accept a `GeneratorFunction` and returns a `Promise`
that allow for composability.## example
We can use `gean` to create simple a `fetch` function backed by
[superagent](https://github.com/visionmedia/superagent). We'll use it to
read from the `randomuser` API and sum the number of `male` and `female`
gender entries per user.```js
'use strict';
import agent from 'superagent';
import gean from 'gean';const fetch = uri => new Promise((yep, nope) => {
agent.get(uri).end((err, res) => err ? nope(err) : yep(res));
});gean(function * () {
const uri = 'https://randomuser.me/api?results=10';
const res = yield fetch(uri);
const results = res.body.results;
const counter = {female: 0, male: 0};for (let result of results)
counter[result.user.gender]++;console.log(counter)
// { female: 8, male: 2 }
});
```## license
MIT