{"id":19050513,"url":"https://github.com/blakek/partition","last_synced_at":"2026-06-18T06:31:10.026Z","repository":{"id":40812875,"uuid":"281224494","full_name":"blakek/partition","owner":"blakek","description":"🗂 Partition an array or other iterable into two or more parts","archived":false,"fork":false,"pushed_at":"2023-01-06T12:00:07.000Z","size":1182,"stargazers_count":2,"open_issues_count":12,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-12T06:03:16.817Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blakek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-20T20:59:05.000Z","updated_at":"2020-11-23T15:58:16.000Z","dependencies_parsed_at":"2023-02-06T01:01:40.780Z","dependency_job_id":null,"html_url":"https://github.com/blakek/partition","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/blakek/partition","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakek%2Fpartition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakek%2Fpartition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakek%2Fpartition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakek%2Fpartition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blakek","download_url":"https://codeload.github.com/blakek/partition/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakek%2Fpartition/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34479552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-08T23:15:10.405Z","updated_at":"2026-06-18T06:31:10.010Z","avatar_url":"https://github.com/blakek.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# partition\n\n\u003e 🗂 Partition an array or other iterable into two or more parts\n\n`partition()` is like `[].filter()` except you get the `true` and `false`\nresults as separate arrays.\n\n`partitionMap()` is like `partition()`, but instead of `true`/`false`, results\nare grouped by the return value of the passed function.\n\n## Install\n\nUsing [Yarn]:\n\n```bash\n$ yarn add @blakek/partition\n```\n\n…or using [npm]:\n\n```bash\n$ npm i --save @blakek/partition\n```\n\n## Usage\n\n```js\nimport { partition, partitionMap } from '@blakek/partition';\n\nconst isEven = n =\u003e n % 2 === 0;\n\nconst [even, odd] = partition([1, 2, 3, 4, 5], isEven);\n\nconsole.log(even); //» [2, 4]\nconsole.log(odd); //» [1, 3, 5]\n\nconst scores = [\n  { initials: 'ABC', score: 125 },\n  { initials: 'CBK', score: 920 },\n  { initials: 'ABC', score: 123 },\n  { initials: 'CBD', score: 420 },\n  { initials: 'CBK', score: 1000 }\n];\n\npartitionMap(scores, x =\u003e x.initials);\n//» Map {\n//»   'ABC' =\u003e [ { initials: 'ABC', score: 125 }, { initials: 'ABC', score: 123 } ],\n//»   'CBK' =\u003e [ { initials: 'CBK', score: 920 }, { initials: 'CBK', score: 1000 } ],\n//»   'CBD' =\u003e [ { initials: 'CBD', score: 420 } ]\n//» }\n```\n\n## API\n\n### `partition`\n\n```ts\nfunction partition\u003cT\u003e(\n  iterable: Iterable\u003cT\u003e,\n  partitionFunction: (value?: T, index?: number, array?: T[]) =\u003e boolean\n): [T[], T[]];\n```\n\nSplits an array into two parts: those where the partition function was truthy,\nand those where it was falsy.\n\n### `partitionMap`\n\n```ts\nfunction partitionMap\u003cT, U\u003e(\n  iterable: Iterable\u003cT\u003e,\n  partitionFunction: (value?: T, index?: number, array?: T[]) =\u003e U\n): Map\u003cU, T[]\u003e;\n```\n\nCreates a `Map` from the returns of the partition function.\n\n```js\npartitionMap([1, 2, 3, 4, 5], n =\u003e n % 2 == 0);\n//» Map(2) { false =\u003e [ 1, 3, 5 ], true =\u003e [ 2, 4 ] }\n\nconst name = n =\u003e {\n  if (n \u003c 3) return 'small';\n  if (n \u003c 7) return 'medium';\n  return 'large';\n};\n\npartitionMap(new Set([1, 2, 3, 4, 5, 6, 7, 8]), n =\u003e name(n));\n//» Map(3) {\n//»   'small' =\u003e [ 1, 2 ],\n//»   'medium' =\u003e [ 3, 4, 5, 6 ],\n//»   'large' =\u003e [ 7, 8 ]\n//» }\n```\n\n## Contributing\n\n[Node.js] and [Yarn] are required to work with this project.\n\nTo install all dependencies, run:\n\n```bash\nyarn\n```\n\n### Useful Commands\n\n|                     |                                                 |\n| ------------------- | ----------------------------------------------- |\n| `yarn build`        | Builds the project to `./dist`                  |\n| `yarn format`       | Format the source following the Prettier styles |\n| `yarn test`         | Run project tests                               |\n| `yarn test --watch` | Run project tests, watching for file changes    |\n\n## License\n\nMIT\n\n[node.js]: https://nodejs.org/\n[npm]: https://npmjs.com/\n[yarn]: https://yarnpkg.com/en/docs/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakek%2Fpartition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblakek%2Fpartition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakek%2Fpartition/lists"}