{"id":20181752,"url":"https://github.com/nichoth/continuable-fp","last_synced_at":"2025-09-02T13:36:21.756Z","repository":{"id":57206540,"uuid":"96004575","full_name":"nichoth/continuable-fp","owner":"nichoth","description":"Rewriting continuable operators, but with the arguments flipped","archived":false,"fork":false,"pushed_at":"2021-08-30T23:15:49.000Z","size":19,"stargazers_count":6,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T06:22:30.189Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nichoth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-02T05:35:53.000Z","updated_at":"2021-08-30T23:15:52.000Z","dependencies_parsed_at":"2022-09-11T05:20:23.632Z","dependency_job_id":null,"html_url":"https://github.com/nichoth/continuable-fp","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fcontinuable-fp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fcontinuable-fp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fcontinuable-fp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fcontinuable-fp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nichoth","download_url":"https://codeload.github.com/nichoth/continuable-fp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999840,"owners_count":21031044,"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-14T02:36:39.385Z","updated_at":"2025-04-10T05:10:53.208Z","avatar_url":"https://github.com/nichoth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# continuable fp\n\n[Continuable](https://github.com/Raynos/continuable) operators, but with the arguments flipped so they compose better, and also they curry automatically. So this is `operator(function, data)`.\n\nThis is a fun way to play with IO and functional patterns.\n\n## install\n```\nnpm i -S continuable-fp\n```\n\n## example\n\n```js\nvar compose = require('compose-function')\nvar c = require('./')\n\nvar excitedly = compose(\n    // remove a level of nesting\n    c.join,\n    c.map(function (data) {\n        // return a nested continuable\n        // here you can make a call to a new continuable (`someIO` below),\n        // using the data inside this continuable\n        return c.either(\n            // call this if `someIO` returns an error\n            function onErr (err) {\n                return c.of('booo')\n            },\n            function (val) {\n                return c.of(val)\n            },\n            someIO(data + ' wooo')\n        )\n    }),\n    c.map(function (data) {\n        return data + '!!!'\n    })\n)\n\nexcitedly(someIO('this is a value'))(function (err, val) {\n    console.log(err, val)\n    // null 'this is a value!!! wooo'\n})\n\nfunction someIO (data, cb) {\n    if (!cb) return function (_cb) {\n        return someIO(data, _cb)\n    }\n    process.nextTick(function () {\n        cb(null, data)\n    })\n}\n\nfunction ioError (data, cb) {\n    if (!cb) return function (_cb) {\n        return ioError(data, _cb)\n    }\n    process.nextTick(function () {\n        cb(new Error('rarrr'))\n    })\n}\n```\n\n## example of errors\n\n```js\nvar c = require('./')\n\nvar myFn = c.either(\n    function onErr (err) {\n        return c.of(err + ' baaaa')\n    },\n    function onData (data) {\n        return c.of('ok')\n    }\n)\n\nmyFn(someIO('woooo'))(function (err, done) {\n    console.log('it worked...', err, done)\n    // it worked... null ok\n})\n\nmyFn(ioError('booo'))(function (err, ok) {\n    console.log('err result...', err, ok)\n    // err result... null Error: booo baaaa\n})\n\nfunction someIO (data, cb) {\n    if (!cb) return function (_cb) {\n        return someIO(data, _cb)\n    }\n    process.nextTick(function () {\n        cb(null, data)\n    })\n}\n\nfunction ioError (data, cb) {\n    if (!cb) return function (_cb) {\n        return ioError(data, _cb)\n    }\n    process.nextTick(function () {\n        cb(new Error('' + data))\n    })\n}\n```\n\n```\n$ node err-example.js\nit worked... null ok\nerr result... null Error: booo baaaa\n```\n\n## typescript\n\nYou can use typescript too\n\n```\n$ npx tsc ts-example.ts\nts-example.ts:7:9 - error TS2339: Property 'thisdoesnotexist' does not exist on type 'string'.\n\n7     val.thisdoesnotexist()\n          ~~~~~~~~~~~~~~~~\n\n```\n\n```typescript\nimport c = require('continuable-fp')\n\nvar test: c.Continuable\u003cstring\u003e = c.of('hello')\n\nc.of('hello')(function (err, val) {\n    val.thisdoesnotexist()\n    // Property 'thisdoesnotexist' does not exist on type 'string'\n})\n```\n\n## operators\n\n### join\nTake a nested continuable and return the inner one\n\n### map\nMap a value through a predicate function\n\n### either\nReturn the left function if there is an error, right function if there's no error.\n\n```js\neither (left, right, continuable)\n```\n\n### of\nTake a value, and create a continuable of it\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Fcontinuable-fp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnichoth%2Fcontinuable-fp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Fcontinuable-fp/lists"}