{"id":20838810,"url":"https://github.com/royalicing/itsybitsy","last_synced_at":"2026-04-13T02:40:39.055Z","repository":{"id":62422342,"uuid":"405385689","full_name":"RoyalIcing/itsybitsy","owner":"RoyalIcing","description":"Map, filter, flat map, reduce — all in one place","archived":false,"fork":false,"pushed_at":"2022-01-11T03:51:59.000Z","size":328,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-18T23:44:08.469Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/RoyalIcing.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":"2021-09-11T13:24:24.000Z","updated_at":"2022-10-24T04:14:41.000Z","dependencies_parsed_at":"2022-11-01T17:45:35.612Z","dependency_job_id":null,"html_url":"https://github.com/RoyalIcing/itsybitsy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2Fitsybitsy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2Fitsybitsy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2Fitsybitsy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2Fitsybitsy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RoyalIcing","download_url":"https://codeload.github.com/RoyalIcing/itsybitsy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243196662,"owners_count":20251861,"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":[],"created_at":"2024-11-18T01:11:37.054Z","updated_at":"2025-12-26T02:40:48.427Z","avatar_url":"https://github.com/RoyalIcing.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e🕷🕸 itsybitsy\u003c/h1\u003e\n  \u003cp\u003eMap, filter, flat map, reduce — all with the one function\u003c/p\u003e\n  \u003ca href=\"https://bundlephobia.com/result?p=itsybitsy\"\u003e\n    \u003cimg src=\"https://badgen.net/bundlephobia/minzip/itsybitsy@0.1.0\" alt=\"minified and gzipped size\"\u003e\n    \u003cimg src=\"https://badgen.net/bundlephobia/min/itsybitsy@0.1.0\" alt=\"minified size\"\u003e\n    \u003cimg src=\"https://badgen.net/bundlephobia/dependency-count/itsybitsy@0.1.0\" alt=\"zero dependencies\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n## Install\n\n```console\nnpm add itsybitsy\n```\n\n## Examples\n\n### Map\n\n```ts\nimport { bitsy } from \"itsybitsy\";\n\nfunction* toString(n: number) {\n  yield n.toString();\n}\n\nconst numbers = [1, 2, 3];\nconst strings = [...bitsy(toString).from(numbers)];\n// [\"1\", \"2\", \"3\"]\n```\n\n### Filter\n\n```ts\nimport { bitsy } from \"itsybitsy\";\n\nfunction* whereEven(item: number) {\n  if (item % 2 === 0) yield item;\n}\n\nconst numbers = [1, 2, 3, 4, 5, 6];\nconst evens = [...bitsy(whereEven).from(numbers)];\n// [2, 4, 6]\n```\n\n### Reduce\n\n```ts\nimport { bitsy } from \"itsybitsy\";\n\nfunction* count(_item: unknown, accum: number) {\n  return accum + 1;\n}\n\nfunction* sum(item: number, accum: number) {\n  return accum + item;\n}\n\nconst numbers = [1, 2, 3, 4, 5, 6];\nconst totalCount = bitsy(count, 0).result(numbers); // 6\nconst totalSum = bitsy(sum, 0).result(numbers); // 21\n```\n\n### Flat map\n\n```ts\nimport { bitsy } from \"itsybitsy\";\n\nfunction* repeatEvens(item: number) {\n  if (item % 2 === 0) {\n    yield item;\n    yield item;\n  } else {\n    yield item;\n  }\n}\n\nconst numbers = [1, 2, 3, 4, 5, 6];\nconst withEvensRepeated = [...bitsy(repeatEvens).from(numbers)];\n// [1, 2, 2, 3, 4, 4, 5, 6, 6]\n```\n\n### Compact\n\n```ts\nimport { bitsy } from \"itsybitsy\";\n\nfunction* compact\u003cT\u003e(item: T): Generator\u003cExclude\u003cT, null | undefined | false\u003e\u003e {\n  if (item == null || (typeof item === 'boolean' \u0026\u0026 item === false)) return;\n  yield item as Exclude\u003cT, null | undefined | false\u003e;\n}\n\nconst itemsWithFalsey = [0, 1, false, 2, true, 3, null, 4, undefined, 5];\nconst itemsWithoutFalsey = [...bitsy(compact).from(itemsWithFalsey)];\n// [0, 1, 2, true, 3, 4, 5]\n```\n\n### Chunk into pairs\n\n```ts\nimport { bitsy } from \"itsybitsy\";\n\nfunction* chunk2(item: string | number, accum: undefined | unknown) {\n  if (accum === undefined) {\n    return item;\n  } else {\n    yield [accum, item];\n    return;\n  }\n}\n\nconst pairsFlat = [\n  \"/\",\n  8,\n  \"/about\",\n  3,\n  \"/docs/api\",\n  2,\n  \"/pricing\",\n  1,\n];\nconst pairs = [...bitsy(chunk2, undefined).from(pairsFlat)];\n// [ [\"/\", 8], [\"/about\", 3], [\"/docs/api\", 2], [\"/pricing\", 1] ]\n```\n\n### Chaining with `.then`\n\n```ts\nimport { bitsy } from \"itsybitsy\";\n\nfunction* add1(item: number) {\n  yield item + 1;\n}\n\nfunction* toString(item: number) {\n  yield item.toString();\n}\n\nfunction* repeatEvens(item: number) {\n  if (item % 2 === 0) {\n    yield item;\n    yield item;\n  } else {\n    yield item;\n  }\n}\n\nconst numbers = [1, 2, 3, 4, 5];\nconst strings = [...bitsy(add1).then(repeatEvens).then(toString).from(numbers)];\n// [\"2\", \"2\", \"3\", \"4\", \"4\", \"5\", \"6\", \"6\"]\n```\n\n----\n\nAlternative name: forte?\n\n```ts\nconst strings = [...forte(addOne).then(toString).of(numbers)];\n\nconst totalCount = forte(count, 0).reduce(numbers);\n```\n\n----\n\nAlternative API\n\n```ts\nbitsy({\n  *0(n: number) {\n    if (n % 2 === 0) yield n;\n  },\n  *1(n: number) {\n    yield n.toString();\n  },\n  *2(s: string) {\n    yield `#${s}`;\n  }\n}).from([1, 2, 3, 4, 5, 6]);\n// [\"#2\", \"#4\", \"#6\"]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyalicing%2Fitsybitsy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froyalicing%2Fitsybitsy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyalicing%2Fitsybitsy/lists"}