{"id":19793586,"url":"https://github.com/darky/context-fp","last_synced_at":"2025-05-01T02:30:44.467Z","repository":{"id":222886726,"uuid":"758598999","full_name":"darky/context-fp","owner":"darky","description":"Microscopic functional programming context for TypeScript","archived":true,"fork":false,"pushed_at":"2024-12-29T19:12:06.000Z","size":124,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-25T21:52:18.650Z","etag":null,"topics":["context","dependency","di","fp","functional","functional-programming","injection","javascript","js","programming","ts","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/darky.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-16T17:01:26.000Z","updated_at":"2024-12-29T19:12:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"d94eeb15-52e0-4a99-81e5-22861dbf220e","html_url":"https://github.com/darky/context-fp","commit_stats":null,"previous_names":["darky/context-fp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Fcontext-fp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Fcontext-fp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Fcontext-fp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darky%2Fcontext-fp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darky","download_url":"https://codeload.github.com/darky/context-fp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251812267,"owners_count":21647876,"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":["context","dependency","di","fp","functional","functional-programming","injection","javascript","js","programming","ts","typescript"],"created_at":"2024-11-12T07:10:28.247Z","updated_at":"2025-05-01T02:30:44.462Z","avatar_url":"https://github.com/darky.png","language":"TypeScript","readme":"# context-fp\n\n## Deprecated in favor [klubok](https://github.com/darky/klubok)\n\n![logo](logo.png)\n\nMicroscopic functional programming context for TypeScript \u003cbr/\u003e\n\n## Motivation\n\nif you tired from gygantic TypeScript DI containers, based on classes and decorators, you are in the right place \u003cbr/\u003e\nJust use functional programming and don't worry about context passing through functions, it's with you\n\n## Features\n\n* 🤏 Microscopic, few kilobytes size and most of it is TypeScript generics\n* 💉 Dependency injection without classes and decorators, only functions\n* 🤌 Functions cached during workflow, no excess cost of CPU\n* 💡 Smart type inference, only describe type of context and rest will be inferred\n* ♻️ Unit tests friendly, feel free to call any function directly in the workflow\n* 📦 Tiny Redux like state manager also attached\n\n## How to\n\n#### Basic example\n\n```typescript\nimport { cfp } from 'context-fp'\nimport assert from 'node:assert'\n\ntype Context = { numbers: number[] }\n\nconst positiveNumbers = ({ numbers }: Context) =\u003e numbers.filter(n =\u003e n \u003e 0)\n\nconst numbersPrefix = () =\u003e 'Here is numbers:'\n\nconst positiveNumbersAsString = cfp(\n  numbersPrefix,\n  positiveNumbers,\n  (prefix, numbers) =\u003e `${prefix} ${numbers.toString()}`\n)\n\nassert.strictEqual(\n  positiveNumbersAsString({ numbers: [-1, -5, 7, 0, 4] }),\n  'Here is numbers: 7,4'\n)\n```\n\n#### Calculations cached example\n\n```typescript\nimport { cfp } from 'context-fp'\nimport assert from 'node:assert'\n\nlet called = 0\n\nconst positiveNumbers = ({ numbers }: { numbers: number[] }) =\u003e\n  (called++, numbers.filter(n =\u003e n \u003e 0))\n\nconst positiveNumbersLength = cfp(positiveNumbers, ns =\u003e ns.length)\n\nconst positiveNumbersAsString = cfp(\n  positiveNumbers,\n  positiveNumbersLength,\n  (ns, l) =\u003e `${ns.toString()}; length - ${l}`\n)\n\nassert.strictEqual(\n  positiveNumbersAsString({ numbers: [-1, -5, 7, 0, 4] }),\n  '7,4; length - 2'\n)\nassert.strictEqual(called, 1)\n```\n\n#### Unit tests example\n\n```typescript\nimport { cfp } from 'context-fp'\nimport assert from 'node:assert'\n\ntype Context = { numbers: number[] }\n\nconst positiveNumbers = ({ numbers }: Context) =\u003e numbers.filter(n =\u003e n \u003e 0)\n\nconst numbersPrefix = () =\u003e 'Here is numbers:'\n\nconst positiveNumbersAsString = cfp(\n  numbersPrefix,\n  positiveNumbers,\n  (prefix, numbers) =\u003e `${prefix} ${numbers.toString()}`\n)\n\nassert.strictEqual(\n  positiveNumbersAsString.raw('Here is numbers:', [7, 4]),\n  'Here is numbers: 7,4'\n)\n```\n\n#### Dependency injection example\n\n```typescript\nimport { cfp } from 'context-fp'\nimport assert from 'node:assert'\n\nconst fetchUserFromDB = async (): Promise\u003c{ name: string }\u003e =\u003e {\n  // some production implementation\n}\n\nconst fetchUser = ({ fetchUser }: { fetchUser?: typeof fetchUserFromDB }) =\u003e\n  fetchUser?.() ?? fetchUserFromDB()\n\nconst helloWorldUser = cfp(\n  fetchUser,\n  user =\u003e user.then(({ name }) =\u003e `Hello world, ${name}!`)\n)\n\nassert.strictEqual(\n  await helloWorldUser({ fetchUser: async () =\u003e ({ name: 'Vasya' }) }),\n  'Hello world, Vasya!'\n)\n```\n\n#### State manager example\n\n```typescript\nimport { cfp, sfp } from 'context-fp'\nimport assert from 'node:assert'\n\nconst numbers = ({ incNumber }: { incNumber: number }) =\u003e\n  sfp((ns: number[], n: number) =\u003e [...ns, n + incNumber], [])\n\nconst addNumber1 = cfp(numbers, ns =\u003e ns(1))\nconst addNumber2 = cfp(numbers, ns =\u003e ns(2))\nconst addNumber3 = cfp(numbers, ns =\u003e ns(3))\n\nconst numbersToString = cfp(\n  numbers,\n  addNumber1,\n  addNumber2,\n  addNumber3,\n  ns =\u003e ns().toString()\n)\n\nassert.strictEqual(numbersToString({ incNumber: 1 }), '2,3,4')\n```\n\n## See also\n\n* [context-fp-go](https://github.com/darky/context-fp-go) - Functional programming context for Golang\n* [functx](https://github.com/darky/functx) - Functional programming context for Gleam\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarky%2Fcontext-fp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarky%2Fcontext-fp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarky%2Fcontext-fp/lists"}