{"id":17949729,"url":"https://github.com/slurmulon/generator-collector","last_synced_at":"2025-04-03T15:43:04.117Z","repository":{"id":74678884,"uuid":"548994875","full_name":"slurmulon/generator-collector","owner":"slurmulon","description":":recycle: Lazily collect and query generators","archived":false,"fork":false,"pushed_at":"2024-04-15T06:46:11.000Z","size":924,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-29T10:07:02.804Z","etag":null,"topics":["coroutine","generator","iteration","iterator","lazy","query"],"latest_commit_sha":null,"homepage":"https://slurmulon.github.io/generator-collector","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slurmulon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"docs/roadmap.md","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-10T14:05:58.000Z","updated_at":"2023-08-17T22:40:04.000Z","dependencies_parsed_at":"2024-12-16T18:38:16.694Z","dependency_job_id":"d0efcb48-2c6a-47b4-a9e1-ebf7db82db0f","html_url":"https://github.com/slurmulon/generator-collector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slurmulon%2Fgenerator-collector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slurmulon%2Fgenerator-collector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slurmulon%2Fgenerator-collector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slurmulon%2Fgenerator-collector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slurmulon","download_url":"https://codeload.github.com/slurmulon/generator-collector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247030865,"owners_count":20872196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coroutine","generator","iteration","iterator","lazy","query"],"created_at":"2024-10-29T09:32:31.414Z","updated_at":"2025-04-03T15:43:04.101Z","avatar_url":"https://github.com/slurmulon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# generator-collector\n\u003e :recycle: Lazily collect and query generators in JS\n---\n\n\u003e :warning: This project is **experimental** and should not be considered stable for production use.\n\n## Features\n\n- Collect and query generator results using coroutines\n- Iterate only to the values you need, only when you need them\n- Seamless integration with promises and async functions\n\n## Resources\n\n- :book: [Documentation](https://slurmulon.github.io/generator-collector)\n- :anchor: [Install](https://slurmulon.github.io/generator-collector/#/install)\n- :wrench: [API](https://slurmulon.github.io/generator-collector/#/api/)\n- :bulb: [Usage and Examples](https://slurmulon.github.io/generator-collector/#/usage)\n\n## Example\n\nThe following `node` example uses `generator-collector` and `js-coroutines` to query for the 5 best red wines in France.\n\n```js\nimport { collector, promiser, each } from 'generator-collector'\nimport { map, sort } from 'js-coroutines' // optional, but plays nice with other coroutine libraries\n\nasync function wine () {\n  const categories = ['reds', 'whites', 'sparkling', 'rose', 'dessert', 'port']\n\n  // Create a generator-based \"promiser\" (coroutine) that loads and sorts a list of wines within a category\n  const api = promiser(function* (category = 'reds') {\n    const response = yield fetch(`https://api.sampleapis.com/wines/${category}`)\n    const data = yield response.json()\n\n    const rated = yield* sort(data, function* (a, b) {\n      return yield b.rating.average - a.rating.average\n    })\n\n    const items = yield* map(rated, function* (item) {\n      return yield { ...item, category }\n    })\n\n    return items\n  })\n\n  // Create a collector that reduces each result from the queried API responses into a single collection\n  const load = collector(function* (query = null) {\n    yield* each(query ?? categories, api)\n  }, {\n    // Override default insert behavior of `push.call` (now `push.apply`).\n    // Enables flat reduction of each item in the API responses ([a, b, c] vs. [[a], [b], [c]]).\n    insert: (store, value) =\u003e Array.prototype.push.apply(store, value)\n  })\n\n  // Invoke our data fetching collector for red wines (call `load()` instead for all wine categories)\n  const query = load(['reds'])\n\n  // Load all the red wines from the API (since we need the full list to know the \"best\")\n  const all = await query.all()\n\n  // Scan results for the top 5 best red wines from France\n  const best = await query.take(5, (item) =\u003e item.location.startsWith('France'), true)\n\n  return { all, best }\n}\n\nwine().then(result =\u003e {\n  console.log('Loaded best red wines in France', result.best, result.all.length)\n\n  process.exit(0)\n})\n```\n\n## Contact \u0026 Support\n\n-  Create a [GitHub issue](https://github.com/slurmulon/generator-collector/issues) for bug reports, feature requests, or questions\n-   Add a ⭐️ [star on GitHub](https://github.com/slurmulon/generator-collector) or ❤️ [tweet](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Fslurmulon%2Fgenerator-collector\u0026hashtags=js,generators,promises,queries) to support the project!\n\n## License\n\nCopyright © Erik Vavro. All rights reserved.\n\nLicensed under the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslurmulon%2Fgenerator-collector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslurmulon%2Fgenerator-collector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslurmulon%2Fgenerator-collector/lists"}