{"id":19094491,"url":"https://github.com/risto-stevcev/lazy-either","last_synced_at":"2025-04-30T13:03:33.616Z","repository":{"id":66361964,"uuid":"52914940","full_name":"Risto-Stevcev/lazy-either","owner":"Risto-Stevcev","description":":twisted_rightwards_arrows: A lazy implementation of the Fantasy Land Either type","archived":false,"fork":false,"pushed_at":"2017-05-22T11:47:34.000Z","size":16,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-09T11:27:48.168Z","etag":null,"topics":["either","fantasy-land","lazy"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/lazy-either","language":"JavaScript","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/Risto-Stevcev.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}},"created_at":"2016-03-01T22:28:02.000Z","updated_at":"2024-03-22T17:48:15.000Z","dependencies_parsed_at":"2023-09-23T18:51:59.414Z","dependency_job_id":null,"html_url":"https://github.com/Risto-Stevcev/lazy-either","commit_stats":{"total_commits":12,"total_committers":2,"mean_commits":6.0,"dds":"0.16666666666666663","last_synced_commit":"12d3385e98e12acccfd3adc7581da60f5746033c"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Risto-Stevcev%2Flazy-either","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Risto-Stevcev%2Flazy-either/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Risto-Stevcev%2Flazy-either/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Risto-Stevcev%2Flazy-either/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Risto-Stevcev","download_url":"https://codeload.github.com/Risto-Stevcev/lazy-either/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223782347,"owners_count":17201766,"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","fantasy-land","lazy"],"created_at":"2024-11-09T03:29:56.734Z","updated_at":"2024-11-09T03:29:57.333Z","avatar_url":"https://github.com/Risto-Stevcev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\n\n🦋 [Fluture](https://github.com/fluture-js/Fluture) is a similar project but which is actively developed and provides more features.\n\n---\n\n# LazyEither\n\n[![Build Status](https://travis-ci.org/Risto-Stevcev/lazy-either.svg)](https://travis-ci.org/Risto-Stevcev/lazy-either)\n\nThe `LazyEither` type is used to represent a lazy `Either` value. It is similar to the `Future` and `Promise` types. The constructor continuation function parameter and *eventual* return value is an `Either` type. The execution is delayed until the value is requested using one of it's methods.\n\nThe implementation is more favorable than the `Future` type because it is very easy to compose elegant pipelines, and it handles errors nicely. If `fork`-like branching is desired, it can be done just by resolving the pipeline using `value` and checking whether the result `isLeft` or `isRight` (though branching is not usually needed). See the examples section for more details.\n\nThe implementation follows the [Fantasy Land](https://github.com/fantasyland/fantasy-land) specifications. The `LazyEither` type is a `Functor`, `Applicative` and `Monad`. It is not (necessarily) a `Setoid` due to its lazy/deferred nature.\n\n\n## Construction\n\nThe `LazyEither` type consists of a single constructor that accepts a function which must accept a continuation function used to resolve the `LazyEither` instance into an `Either` type:\n\n```hs\nLazyEither :: ((Either e a -\u003e ()) -\u003e ()) -\u003e LazyEither e a\n```\n\nThe resolved instance should be an [Either type](https://github.com/ramda/ramda-fantasy/blob/master/docs/Either.md).\n\n\n```js\n//:: (Number, a) -\u003e LazyEither (Either e a)\nlet delayed = (ms, val) =\u003e LazyEither(resolve =\u003e {\n  ms \u003e 1000 ? resolve(S.Left(Error('Delay too long')))\n            : setTimeout(() =\u003e resolve(S.Right(val)), ms)\n})\n```\n\n```js\ndelayed(500, 'Hello').value(console.log)  // returns Right('Hello')\ndelayed(1001, 'Hey').value(console.log)  // returns Left(Error('Delay too long'))\n```\n\n\n## Interaction\n\nOnce a `LazyEither` instance has been created, the various methods attached to the instance can be used to instruct further transformations to take place. Nothing is actually executed until the `value` or `fantasy-land/equals` method is called.\n\nThe `fantasy-land/map`, `fantasy-land/ap` and `fantasy-land/chain` functions can be used to transform resolved values of a `LazyEither` instance.\n\n```js\n//:: String -\u003e String -\u003e String\nconst join = S.curry2(path.join)\n\n//:: String -\u003e LazyEither (Either e [String])\nconst ls = path =\u003e LazyEither(resolve =\u003e\n  fs.readdir(path, (err, files) =\u003e resolve(err ? S.Left(err) : S.Right(S.map(join(path), files)))))\n\n//:: String -\u003e LazyEither (Either e String)\nconst cat = file =\u003e LazyEither(resolve =\u003e\n  fs.readFile(file, {encoding: 'utf8'}, (err, data) =\u003e resolve(err ? S.Left(err) : S.Right(data))))\n\n//:: String -\u003e LazyEither (Either e String)\nconst catDir =\nS.pipe([ls,\n        S.chain(S.traverse(LazyEither, cat)),\n        S.map(S.unlines)])\n```\n\nA `LazyEither` instance is executed when `value` or `fantasy-land/equals` gets called:\n\n```js\ncatDir(os.homedir()).value(S.either(console.error, console.log))\n```\n\n\n## Reference\n\n### Constructors\n\n#### `LazyEither`\n\n```hs\n:: ((Either e a -\u003e ()) -\u003e ()) -\u003e LazyEither e a\n```\n\nConstructs a `LazyEither` instance that represents some action that may possibly fail. It takes a function which must accept a continuation function that takes an `Either` type used to represent success or failure.\n\n#### `LazyEither.Right`\n\n```hs\n:: a -\u003e LazyEither e a\n```\n\nCreates a `LazyEither` instance that resolves to a `Right` with the given value.\n\n#### `LazyEither.Left`\n\n```hs\n:: e -\u003e LazyEither e a\n```\n\nCreates a `LazyEither` instance that resolves to a `Left` with the given value.\n\n\n### Static methods\n\n#### `LazyEither['fantasy-land/of']`\n\n```hs\n:: a -\u003e LazyEither e a\n```\n\nCreates a pure instance that resolves to a `Right` with the given value.\n\n#### `LazyEither.lift`\n\n```hs\n:: (a -\u003e b) -\u003e a -\u003e LazyEither e b\n```\n\nLifts a function of arity `1` into one that returns a `LazyEither` instance.\n\n#### `LazyEither.liftN`\n\n```hs\n:: n -\u003e (a -\u003e .. -\u003e z) -\u003e a -\u003e .. -\u003e z -\u003e LazyEither e z\n```\n\nLifts a function of arity `n` into one that returns a `LazyEither` instance.\n\n#### `LazyEither.promote`\n\n```hs\n:: Either a b -\u003e LazyEither a b\n```\n\nPromotes an `Either` type to a `LazyEither` type.\n\n\n### Instance methods\n\n#### `lazyEither['fantasy-land/map']`\n\n```hs\n:: LazyEither e a ~\u003e (a -\u003e b) -\u003e LazyEither e b\n```\n\nTransforms the resolved `Either` value of this `LazyEither` instance with the given function. If the instance resolves as a `Left` value, the provided function is not called and the returned `LazyEither` instance will resolve with that `Left` value.\n\n#### `lazyEither['fantasy-land/ap']`\n\n```hs\n:: LazyEither e a ~\u003e LazyEither e (a -\u003e b) -\u003e LazyEither e b\n```\n\nApplies the `Either` function of the provided `LazyEither` instance to the `Either` value of this `LazyEither` instance, producing a `LazyEither` instance of the result. If either `LazyEither` resolves as a `Left` value, then the returned `LazyEither` instance will resolve with that `Left` value.\n\n#### `lazyEither['fantasy-land/chain']`\n\n```hs\n:: LazyEither e a ~\u003e (a -\u003e LazyEither e b) -\u003e LazyEither e b\n```\n\nCalls the provided function with the value of this `LazyEither` instance, returning the new `LazyEither` instance. If either `LazyEither` instance resolves as a `Left` value, the returned `LazyEither` instance will resolve with that `Left` value. The provided function can be used to try to recover the error.\n\n#### `lazyEither['fantasy-land/bimap']`\n\n```hs\n:: LazyEither e a ~\u003e (e -\u003e f) -\u003e (a -\u003e b) -\u003e LazyEither f b\n```\n\nUses the provided functions to transform this `LazyEither` instance when it resolves to a `Left` or a `Right` value, respectively.\n\n#### `lazyEither.value`\n\n```hs\n:: LazyEither e a ~\u003e (Either e a -\u003e ()) -\u003e ()\n```\n\nCalls the provided function with the value of this `LazyEither` instance without returning a new `LazyEither` instance. It is similar to `Future.fork`. This function can be used as a final processing step for the returned `Either` value, or to create a branch of two seperate execution streams to handle the resolved `Left` or `Right` value.\n\n#### `lazyEither['fantasy-land/equals']`\n\n```hs\n:: LazyEither a b ~\u003e LazyEither c d -\u003e (Boolean -\u003e ()) -\u003e ()\n```\n\nCompares the `Either` value of this `LazyEither` instance with the `Either` value of the provided `LazyEither` instance, and calls the provided function with the `Boolean` result of the comparison. Like `value`, this function will resolve the pipeline. The result will return `true` if both `Either` values match or `false` if they do not match.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fristo-stevcev%2Flazy-either","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fristo-stevcev%2Flazy-either","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fristo-stevcev%2Flazy-either/lists"}