{"action":"created","issue":{"url":"https://api.github.com/repos/ramda/ramda/issues/1665","repository_url":"https://api.github.com/repos/ramda/ramda","labels_url":"https://api.github.com/repos/ramda/ramda/issues/1665/labels{/name}","comments_url":"https://api.github.com/repos/ramda/ramda/issues/1665/comments","events_url":"https://api.github.com/repos/ramda/ramda/issues/1665/events","html_url":"https://github.com/ramda/ramda/issues/1665","id":136391914,"number":1665,"title":"Proposal to introduce either promises","user":{"login":"Risto-Stevcev","id":6767374,"avatar_url":"https://avatars.githubusercontent.com/u/6767374?v=3","gravatar_id":"","url":"https://api.github.com/users/Risto-Stevcev","html_url":"https://github.com/Risto-Stevcev","followers_url":"https://api.github.com/users/Risto-Stevcev/followers","following_url":"https://api.github.com/users/Risto-Stevcev/following{/other_user}","gists_url":"https://api.github.com/users/Risto-Stevcev/gists{/gist_id}","starred_url":"https://api.github.com/users/Risto-Stevcev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Risto-Stevcev/subscriptions","organizations_url":"https://api.github.com/users/Risto-Stevcev/orgs","repos_url":"https://api.github.com/users/Risto-Stevcev/repos","events_url":"https://api.github.com/users/Risto-Stevcev/events{/privacy}","received_events_url":"https://api.github.com/users/Risto-Stevcev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2016-02-25T13:47:44Z","updated_at":"2016-03-01T00:10:53Z","closed_at":null,"body":"Since promises have an `onRejected` section, it would be nice to be able to chain a bunch of promises that return an `Either` type and have something like `R.liftEitherP` and `R.pipeEitherP`:\r\n\r\n```js\r\n// Wraps a promise into an either type\r\nlet eitherOnFulfilled = (value) => Promise.resolve(S.Right(value))\r\nlet eitherOnRejected = (reason) => Promise.resolve(S.Left(reason))\r\nR.liftEitherP = (promise) => promise.then(eitherOnFulfilled, eitherOnRejected)\r\n```\r\n\r\nThe reasoning being is that you would have something like `pipeEitherP` which won't execute the next promise if it received a `S.Left` value, and you could do something like this:\r\n```js\r\nlet doChecks = body => S.Right(body).chain(condition1).chain(condition2)...\r\nR.pipeEitherP(checkIfExists, update)(doChecks(body))\r\n// Which might return something like:\r\n// S.Left('Condition 1 failed')\r\n// or\r\n// S.Left('Resource does not exist')\r\n// or\r\n// S.Left('Update failed')\r\n// or\r\n// S.Right('Update successful')\r\n```\r\n\r\nI'm pretty new to ramda, so my apologies is this code isn't the best, but hopefully you get the idea behind what I'm trying to do. It's like `pipeP` except that it won't execute all promises if it failed halfway through, and the finishing promise will return an `Either` type.\r\n\r\nPlease let me know if there's a better way to do the above code."},"comment":{"url":"https://api.github.com/repos/ramda/ramda/issues/comments/190459728","html_url":"https://github.com/ramda/ramda/issues/1665#issuecomment-190459728","issue_url":"https://api.github.com/repos/ramda/ramda/issues/1665","id":190459728,"user":{"login":"arcseldon","id":2599332,"avatar_url":"https://avatars.githubusercontent.com/u/2599332?v=3","gravatar_id":"","url":"https://api.github.com/users/arcseldon","html_url":"https://github.com/arcseldon","followers_url":"https://api.github.com/users/arcseldon/followers","following_url":"https://api.github.com/users/arcseldon/following{/other_user}","gists_url":"https://api.github.com/users/arcseldon/gists{/gist_id}","starred_url":"https://api.github.com/users/arcseldon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arcseldon/subscriptions","organizations_url":"https://api.github.com/users/arcseldon/orgs","repos_url":"https://api.github.com/users/arcseldon/repos","events_url":"https://api.github.com/users/arcseldon/events{/privacy}","received_events_url":"https://api.github.com/users/arcseldon/received_events","type":"User","site_admin":false},"created_at":"2016-03-01T00:10:53Z","updated_at":"2016-03-01T00:10:53Z","body":"> Or are you saying to just make everything a Future and call fork whenever? \r\n\r\nNo, I am not saying that."}}