{"id":13496423,"url":"https://github.com/teves-castro/ts-do","last_synced_at":"2025-03-28T18:32:02.059Z","repository":{"id":38272805,"uuid":"118279873","full_name":"teves-castro/ts-do","owner":"teves-castro","description":"Do like notation for typescript using fp-ts","archived":false,"fork":false,"pushed_at":"2023-01-06T01:42:25.000Z","size":1216,"stargazers_count":56,"open_issues_count":4,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-31T11:37:08.519Z","etag":null,"topics":["do-notation","fp-ts","functional-programming"],"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/teves-castro.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":"2018-01-20T20:54:15.000Z","updated_at":"2024-01-17T12:34:32.000Z","dependencies_parsed_at":"2023-02-05T01:46:39.567Z","dependency_job_id":null,"html_url":"https://github.com/teves-castro/ts-do","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teves-castro%2Fts-do","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teves-castro%2Fts-do/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teves-castro%2Fts-do/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teves-castro%2Fts-do/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teves-castro","download_url":"https://codeload.github.com/teves-castro/ts-do/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246080756,"owners_count":20720588,"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":["do-notation","fp-ts","functional-programming"],"created_at":"2024-07-31T19:01:47.658Z","updated_at":"2025-03-28T18:32:00.825Z","avatar_url":"https://github.com/teves-castro.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Description\n\nThis library works as an extension for [fp-ts](https://github.com/gcanti/fp-ts) allowing the usage of a haskell like do notation. One can use exec, bind, sequence and into to chain computations on any of the supplied monads.\nEach bind or sequence in the computation chain contributes to a threaded context that is available to each subsequent step. The exec function can also be used to perform computations that add nothing to the context for their side-effects.\nIt is possible to use this with any monads as long as its kind is defined in fp-ts.\n\n# Installation\n\nTo install the stable version:\n\n```bash\nyarn add ts-do\n```\n\n# Using the extension\n\nStart by importing the extension:\n\n```typescript\nimport { some, map, option } from \"fp-ts/lib/Option\"\nimport { pipe } from \"fp-ts/lib/pipeable\"\nimport { array } from \"fp-ts/lib/Array\"\nimport { range, sum } from \"ramda\"\nimport * as Do from \"ts-do\"\n\nconst bind = Do.bind(option)\nconst into = Do.into(option)\nconst exec = Do.exec(option)\nconst sequence = Do.sequence(array, option)\n\nconst result = pipe(\n  some(3),\n  into(\"x\"), // Chains the computation. Creates a context with { x: 3 }\n  exec(() =\u003e some(undefined)), // Chains the computation. Adds nothing to the context\n  sequence(\"ys\", ({ x }) =\u003e range(0, x).map(() =\u003e some(1))), // Sequences computations. Adds { ys: [1, 1, 1] } to the context\n  map(({ x, ys }) =\u003e x - sum(ys)),\n)\n\n// result === some(0)\n```\n\nCheck the test folder for a few more examples.\n\n# Building\n\nClone the repo\n\n```bash\ngit clone git@github.com:teves-castro/ts-do.git\n```\n\nInstall dependencies\n\n```bash\nyarn\n```\n\nTest\n\n```bash\nyarn run test\n```\n\nCompile\n\n```bash\nyarn run build\n```\n\n# Disclaimer\n\nThese kind of operations (do notation) should be done with compiler support, like the special case of async/await for promises, that is included in most major languages these days.\n\nAlthough these languages are adopting more and more functional programming constructs, sadly more advanced concepts are left out due to not having critical mass to demand it's implementation.\n\nSo, this is an experiment on what can be accomplished without that compiler support. Meaning that if/when this is supported natively by the language itself, certainly with different syntax, this will become obsolete.\n\nAlso I make no commitment to evolve the library beyond my own needs, so bear these warnings in mind when using the library.\nAnd of course I appreciate any comments and suggestions on how to improve or on how I completely blundered something.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteves-castro%2Fts-do","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteves-castro%2Fts-do","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteves-castro%2Fts-do/lists"}