{"id":19146697,"url":"https://github.com/koheing/stream-executor","last_synced_at":"2026-06-17T08:32:10.263Z","repository":{"id":42898484,"uuid":"243513960","full_name":"koheing/stream-executor","owner":"koheing","description":"functional stream programming library","archived":false,"fork":false,"pushed_at":"2023-01-06T02:45:57.000Z","size":568,"stargazers_count":0,"open_issues_count":13,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-23T01:05:03.596Z","etag":null,"topics":["functional-programming","library","typescript"],"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/koheing.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-02-27T12:28:12.000Z","updated_at":"2020-10-31T01:12:36.000Z","dependencies_parsed_at":"2023-02-05T03:45:40.463Z","dependency_job_id":null,"html_url":"https://github.com/koheing/stream-executor","commit_stats":null,"previous_names":["nor-ko-hi-jp/stream-executor"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/koheing/stream-executor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koheing%2Fstream-executor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koheing%2Fstream-executor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koheing%2Fstream-executor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koheing%2Fstream-executor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koheing","download_url":"https://codeload.github.com/koheing/stream-executor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koheing%2Fstream-executor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34441284,"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-17T02:00:05.408Z","response_time":127,"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":["functional-programming","library","typescript"],"created_at":"2024-11-09T07:47:46.178Z","updated_at":"2026-06-17T08:32:10.248Z","avatar_url":"https://github.com/koheing.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stream-executor\n[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)\n![Main](https://github.com/nor-ko-hi-jp/stream-executor/workflows/Main/badge.svg)\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/nor-ko-hi-jp/stream-executor/issues)\n\n- functional stream programming library\n- This library is inspired by [RxJS](https://github.com/ReactiveX/rxjs)\n- This library is effective for\n  - managing and reusing processes in actions in fine-grained\n  - the processing in the action becomes complicated\n  - asynchronous execution sequentially \n\n```\nnpm i stream-executor\n```\n\n# Usage\n\n## 1. chain stream (like RxJS)\n###  using stream-executor\n```ts\nimport { createStream, map, which, filter, tap } from 'stream-executor'\nlet isSucceeded = false\n\nconst chainResult = createStream(1)\n  .chain(\n    map((it) =\u003e it * 10),\n    which(\n      (it) =\u003e it \u003e 1,\n      tap((it) =\u003e (isSucceeded = true)),\n      tap((it) =\u003e console.log('not succeeded'))\n    ),\n    filter((it) =\u003e it \u003e= 10)\n  )\n  .execute()\n\nconsole.log(isSucceeded) // true\nconsole.log(chainResult) // 10\n```\n\n### Not using stream-executor \n```ts\nlet isSucceeded = false\n\nconst initialValue = 1\nlet value = 0\n\nif (value \u003e= 0) {\n  value = initialValue * 10\n}\n\nif (value \u003e 1) {\n  isSucceeded = true\n} else {\n  console.log('not succeeded')\n}\n\nif (value \u003c 10) {\n  return\n}\nconst result = value\n\nconsole.log(isSucceeded) // true\nconsole.log(result)      // 10\n```\n\n\n## 2. batch stream (like switch without break)\n\n###  using stream-executor \n```ts\nimport { createStream, ifRight, which } from 'stream-executor'\n\nconst mammal = { no: 999, name: 'UNKNOWN', type: 'bird' }\nlet isLoading = true\n\ncreateStream(mammal)\n  .batch(\n    (_) =\u003e (isLoading = true),\n    which(\n      ({ type }) =\u003e type === 'bird',\n      (it) =\u003e calculateSize(it),\n      (_) =\u003e console.log('Not Bird')\n    ),\n    ifRight(\n      ({ type, name }) =\u003e type === 'bird' \u0026\u0026 name === 'UNKNOWN',\n      (mammal) =\u003e registerDB(mammal)\n    ),\n    (_) =\u003e (isLoading = false),\n    (_) =\u003e console.log('end')\n  )\n  .execute()\n\nconsole.log(isLoading)    // false\n```\n\n### not using stream-executor \n```ts\nlet isLoading: boolean\nconst mammal = { no: 999, name: 'UNKNOWN', type: 'bird' }\n\nisLoading = true\n\nif (mammal.type === 'bird') {\n  calculateSize(mammal)\n} else {\n  console.log('Not Bird')\n}\n\nif (mammal.type == 'bird' \u0026\u0026 mammal.name !== 'UNKNOWN') {\n  console.log('maybe new species')\n  registerDB(mammal)\n}\n\nisLoading = false\n\nconsole.log('end')\nconsole.log(isLoading)    // false\n```\n\n# 3. asyncChain stream\n\n###  using stream-executor\n```ts\nimport { createStream, tap, map } from 'stream-executor'\nconst result = await createStream(1)\n  .asyncChain(\n    tap(async (it) =\u003e console.log(await it)),             // 1\n    map(async (it) =\u003e await callAPI(it)),    \n    map(async (it) =\u003e parseToModel(await it))      // Record\u003cstring, any\u003e\n  )\n  .execute()\nconsole.log(result) // Record\u003cstring, any\u003e\n``` \n### not using stream-executor \n```ts\n(async () =\u003e {\n  let result\n  const value = 1\n  result = await callAPI(value)\n  result = await parseToModel(result)\n  console.log(result)\n})()\n```\n\n\n# Important\n## 1. About `createStream`\n  - The argument of createStream is not deep copied. use `deepCopy` method if you'd like to do deep copy, please.\n  ```ts\n  import { createStream, tap, deepCopy } from 'stream-executor'\n  const input = { value: 1 }\n  const result = createStream(input)\n    .chain(tap((it) =\u003e (it.value += 9)))\n    .execute()\n\n  console.log(input) // { value: 10 }\n  console.log(result) // { value: 10 }\n\n  const input2 = { value: 1 }\n  const result2 = createStream(deepCopy(input2))\n    .chain(tap((it) =\u003e (it.value += 9)))\n    .execute()\n\n  console.log(input2) // { value: 1 }\n  console.log(result2) // { value: 10 }\n  ```\n## 2. About `deepCopy`\n  - Getter and function in object are removed.\n  ```ts\n  import { createStream, tap, deepCopy } from 'stream-executor'\n  class Wrapper\u003cT\u003e {\n    value: T\n    constructor(value: T) {\n      this.value = value\n    }\n    get doubledValue() {\n      return this.value * 2\n    }\n    hello() {\n      console.log('world')\n    }\n  }\n  const input = new Wrapper(1)\n  const result = createStream(deepCopy(input))\n    .chain(tap((it) =\u003e (it.value += 9)))\n    .execute()\n\n  console.log(input)  // Wrapper{ value: 1, doubledValue: 2, __proto__: { hello: () =\u003e console.log('world') } }\n  console.log(result) // { value: 10, __proto__: {} }\n  ``` \n## 3. About `createStream().chain()`:\n  - Further process is not called if `undefined` returned\n  ```ts\n  import { createStream, tap, filter, map } from 'stream-executor'\n  const result = createStream(1)\n    .chain(\n      tap((it) =\u003e console.log(it)), // 1\n      filter((it) =\u003e it \u003e 2),       // return undefined\n      map((it) =\u003e it + 9)           // not called\n    )\n    .execute()\n  console.log(result) // undefined\n  ``` \n\n## 4. Abount the arguments of execute()\n  - Set the arguments of execute method if you'd like to customize error handling, please\n  ```ts\n  let error: any\n  createStream(1)\n    .batch(\n      (it) =\u003e console.log(it),\n      ..\n    )\n    .execute((err: any) =\u003e {\n      console.error(error)\n      error = err\n    })\n  ```\n\n## 5. Replace `chain` or `batch` executor\n  - Set `option.chainClass` or `option.batchClass` if you would change execution process, please\n  - These Classes are initialized with initialValue as an argument\n  ```ts\n  import { BaseExecutor, createStream } from 'stream-executor'\n  class MockChainExecutor implements BaseExecutor {\n    constructor(public initialValue: any) {}\n    stream(...args: any[]) {\n      return this\n    }\n    execute() {\n      console.log('MockChainExecutor called')\n    }\n  }\n\n  class MockBatchExecutor implements BaseExecutor {\n    constructor(public initialValue: any) {}\n    stream(...args: any[]) {\n      return this\n    }\n    execute() {\n      console.log('MockBatchExecutor called')\n    }\n  }\n\n  createStream(1, { chainClass: MockChainExecutor })\n    .chain((it) =\u003e it)\n    .execute() // 'MockChainExecutor called'\n\n  createStream(1, { batchClass: MockBatchExecutor })\n    .batch((it) =\u003e it)\n    .execute() // 'MockBatchExecutor called'\n  ```\n  \n\n# Utils\n## helper methods and those descriptions in createStream are\n1. [map](./src/executors/helpers/index.ts#L1)\n2. [tap](./src/executors/helpers/index.ts#L16)\n3. [filter](./src/executors/helpers/index.ts#L31)\n4. [which](./src/executors/helpers/index.ts#L46)\n5. [ifRight](./src/executors/helpers/index.ts#L72)\n6. [asTypeOf](./src/executors/helpers/index.ts#L97)\n7. [asInstanceOf](./src/executors/helpers/index.ts#L120)\n8. [stop](./src/executors/helpers/index.ts#L142)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoheing%2Fstream-executor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoheing%2Fstream-executor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoheing%2Fstream-executor/lists"}