{"id":20624259,"url":"https://github.com/ortense/functors","last_synced_at":"2025-08-16T16:51:01.771Z","repository":{"id":214796556,"uuid":"737371154","full_name":"ortense/functors","owner":"ortense","description":"A collection of dependency-free functors written in TypeScript, created to be type-safe, immutable, and lightweight.","archived":false,"fork":false,"pushed_at":"2024-04-18T21:43:00.000Z","size":1365,"stargazers_count":2,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T02:44:48.942Z","etag":null,"topics":["either","either-monad","fp","functional","functional-programming","functors","history-management","lazy","lazy-evaluation","maybe","maybe-monad","monad","monads","state","state-pattern","type-safe","typescript","typescript-library"],"latest_commit_sha":null,"homepage":"https://ortense.github.io/functors/","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/ortense.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2023-12-30T19:38:49.000Z","updated_at":"2024-04-18T21:50:30.000Z","dependencies_parsed_at":"2024-01-02T18:29:09.734Z","dependency_job_id":"290edafe-fc30-4450-8703-7ef38b1753c0","html_url":"https://github.com/ortense/functors","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"9f7a46fb95716b3fbddcdf8463ab40585c6f9b6f"},"previous_names":["ortense/functors"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ortense%2Ffunctors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ortense%2Ffunctors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ortense%2Ffunctors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ortense%2Ffunctors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ortense","download_url":"https://codeload.github.com/ortense/functors/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249074853,"owners_count":21208644,"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":["either","either-monad","fp","functional","functional-programming","functors","history-management","lazy","lazy-evaluation","maybe","maybe-monad","monad","monads","state","state-pattern","type-safe","typescript","typescript-library"],"created_at":"2024-11-16T12:30:14.067Z","updated_at":"2025-04-15T12:45:33.140Z","avatar_url":"https://github.com/ortense.png","language":"TypeScript","readme":"\n![Functors banner - the functors mascot generated by dall-e 2](https://raw.githubusercontent.com/ortense/functors/main/media/mascot.jpg)\n\n# @ortense/functors\n\n[![install size](https://packagephobia.com/badge?p=@ortense/functors)](https://packagephobia.com/result?p=@ortense/functors) [![Coverage Status](https://coveralls.io/repos/github/ortense/mediator/badge.svg?branch=github-actions)](https://coveralls.io/github/ortense/functors?branch=github-actions)\n\nA collection of dependency-free functors written in TypeScript, created to be type-safe, immutable, and lightweight.\n\n## What is a Functor?\n\nIn functional programming, a functor is a concept that represents a type with the ability to be mapped over. This means that you can apply a function to the values inside the type, without altering the structure of the type itself. Functors provide a powerful abstraction for building composable and reusable code, promoting a declarative and functional style of programming.\n\n![functor chart - made in excalidraw.com](https://raw.githubusercontent.com/ortense/functors/main/media/flow.png)\n\n## Overview\n\nThis project is a TypeScript library that embraces the functor concept, offering implementations of common functors. These functors provide useful abstractions for various scenarios in your application, allowing you to write more expressive and maintainable code.\n\n## Install\n\nPick your favorite package manager.\n\n```sh\nnpm install @ortense/functors  # npm\nyarn add  @ortense/functors    # yarn\npnpm add @ortense/functors     # pnpm\nbun add @ortense/functors      # bun\ndeno add @ortense/functors     # deno from jsr.io\n```\n\n## Implemented Functors\n\nFor detailed documentation, please refer to the [official documentation](https://ortense.github.io/functors).\n\n### Lazy\n\nRepresents a lazy-evaluated value, allowing computations to be deferred until needed.\n\n```ts\nimport { lazy } from '@ortense/functors'\n\nconst double = (value: number) =\u003e {\n  console.log('Doubling...')\n  return value * 2\n}\nconst lazyDouble = lazy(() =\u003e 7)\n  .map(double)\n  .map(double)\n\nconst result = lazyDouble.evaluate()\nconsole.log(result)\n// Output:\n// Doubling...\n// Doubling...\n// 42\n```\n\n### History\n\nRepresents a history of values, enabling operations like mapping, resetting, and rolling back to previous states.\n\n```ts\nimport { history } from '@ortense/functors'\n\nconst userHistory = history({ name: 'Jane Doe' })\n  .map(user =\u003e ({ ...user, id: 1 }))\n  .map(({ id }) =\u003e ({ id, name: 'Jonh Due' }))\n\nconsole.log(userHistory.current()) // { id: 1, name: 'Jonh Due' }\nconsole.log(userHistory.rollback().current()) // { id: 1, name: 'Jane Doe' }\nconsole.log(userHistory.reset().current()) // {  name: 'Jane Doe' }\n```\n\n### Either\n\nRepresents a type that can be either of type L or R, providing a mechanism for branching based on success or failure.\n\n```ts\nimport { Either, left, right } from '@ortense/functors'\n\nconst divide = (\n  numerator: number,\n  denominator: number,\n): Either\u003cError, number\u003e =\u003e {\n  if (Number.isNaN(numerator)) {\n    return left(new Error('Numerator is not a number.'))\n  }\n  if (Number.isNaN(denominator)) {\n    return left(new Error('Denominator is not a number.'))\n  }\n\n  if (denominator === 0) {\n    return left(new Error('Division by zero is not posible.'))\n  }\n\n  return right(numerator / denominator)\n}\n\nconst numerator = Number(document.querySelector('input#numerator').value)\nconst denominator = Number(document.querySelector('input#denominator').value)\nconst display = document.querySelector('div#display-result')\n\ndivide(numerator, denominator)\n  .right(result =\u003e {\n    display.textContent = `${numerator} / ${denominator} = ${result}`\n  })\n  .left(error =\u003e {\n    display.textContent = error.message\n  })\n```\n\n### Maybe\n\nRepresents a type that may contain a value or be empty, helping to handle null or undefined values.\n\n```ts\nimport { Maybe, maybe } from '@ortense/functors'\n\ntype User = { id: string; name: string }\n\nconst findUserById = async (id: string): Maybe\u003cUser\u003e =\u003e {\n  const user = await db.users.findByID(id) // suppose that return user or null\n  return maybe\u003cUser\u003e(user)\n};\n\nconst userName = findUserById('123')\n  .map(user =\u003e user.name) // Maybe\u003cstring\u003e\n  .mapEmpty(() =\u003e 'Default Name')\n  .unwrap()\n\nconsole.log(userName) // Output: Default Name (if user not found)\n```\n\n## Contribution\n\nContributions are welcome! Feel free to open issues, submit pull requests, or provide feedback to help improve this library.\n\n## License\n\nThis library is licensed under the MIT License - see the [LICENSE](https://github.com/ortense/functors/blob/main/LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fortense%2Ffunctors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fortense%2Ffunctors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fortense%2Ffunctors/lists"}