{"id":16908700,"url":"https://github.com/zerobias/apropos","last_synced_at":"2025-03-23T17:30:43.807Z","repository":{"id":57098443,"uuid":"99990040","full_name":"zerobias/apropos","owner":"zerobias","description":"Fast strong typed 'Either' data structure for typescript and flow","archived":false,"fork":false,"pushed_at":"2017-12-11T05:58:51.000Z","size":272,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T20:08:15.116Z","etag":null,"topics":["adt","either","fp","functional","maybe","monad"],"latest_commit_sha":null,"homepage":null,"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/zerobias.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}},"created_at":"2017-08-11T04:01:23.000Z","updated_at":"2022-06-06T17:11:50.000Z","dependencies_parsed_at":"2022-08-20T19:40:09.595Z","dependency_job_id":null,"html_url":"https://github.com/zerobias/apropos","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerobias%2Fapropos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerobias%2Fapropos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerobias%2Fapropos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerobias%2Fapropos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zerobias","download_url":"https://codeload.github.com/zerobias/apropos/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245140706,"owners_count":20567431,"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":["adt","either","fp","functional","maybe","monad"],"created_at":"2024-10-13T18:52:33.896Z","updated_at":"2025-03-23T17:30:43.463Z","avatar_url":"https://github.com/zerobias.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apropos\n\nFast strong typed 'Either' data structure for typescript and flow\n\n```bash\n$ npm install --save apropos\n```\n\n[![npm version][npm-image]][npm-url]\n[![Build Status](https://travis-ci.org/zerobias/apropos.svg?branch=master)](https://travis-ci.org/zerobias/apropos)\n\n## API\n\n- [of](#of)\n- [ofL](#ofl)\n- [Right](#right)\n- [Left](#left)\n- [is](#is)\n- [makeError](#makeerror)\n\n```javascript\n//@flow\n\nimport defaultOf, {\n  of,\n  ofL,\n  Right,\n  Left,\n  is,\n  makeError,\n  type Apropos,\n  type MakeError,\n} from 'apropos'\n```\n\n### of\n```javascript\nfunction of\u003cR\u003e(value: R): Apropos\u003cvoid, R\u003e\n```\n\nCreate pure right-handed value, left-handed type is empty.\nExports by default\n\n### ofL\n```javascript\nfunction ofL\u003cL\u003e(value: L): Apropos\u003cL, void\u003e\n```\n\nCreate pure left-handed value, right-handed type is empty.\n\n### Right\n```javascript\nfunction Right\u003c-L, R\u003e(value: R): Apropos\u003cL, R\u003e\n```\n\nCreate right-handed value, left-handed type is inferred from usage.\nTechnically, `Right` returns the same as `of`; the difference is only in the type inference.\n\n### Left\n```javascript\nfunction Left\u003cL, -R\u003e(value: L): Apropos\u003cL, R\u003e\n```\n\nCreate left-handed value, right-handed type is inferred from usage\n\n### is\n```javascript\nfunction is\u003c-T\u003e(value: T): boolean\n```\n\nChecks whether an object is an instance of `Apropos`\n\n### makeError\n\n```javascript\nclass AnnotatedError\u003cContext, Tag\u003e extends Error {\n  tag: Tag\n  data: Context\n}\n\nfunction makeError\u003c-Tag\u003e(tag: Tag): \u003cContext\u003e(data: Context) =\u003e AnnotatedError\u003cContext, Tag\u003e\n```\n\nCreate fabric for generating tagged error constructors.\nUseful in `.mapL`.\n\nSee [annotated errors](#annotated-errors)\n\n## Instance methods\n\n- isRight\n\n- isLeft\n\n\n- equals\n\n- thru\n\n- orElse\n\n- swap\n\n- promise\n\n- fold\n\n\n### Maps\n\n- map\n\n- mapR\n\n- mapL\n\n- bimap\n\n\n### Taps\n\n- tap\n\n- tapR\n\n- tapL\n\n- bitap\n\n\n### Chains\n\n- chain\n\n- chainR\n\n- chainL\n\n- bichain\n\n\n### Conditions\n\n- cond\n\n- chainCond\n\n- logic\n\n\n### Combinations\n\n- alt\n\n- and\n\n- ap\n\n\n## Annotated errors\n\n```typescript\nimport { of, makeError, MakeError, Left } from 'apropos'\n\nconst notNumber: MakeError\u003c'Not a number'\u003e = makeError('Not a number')\nconst isNegative: MakeError\u003c'Negative number'\u003e = makeError('Negative number')\n\nconst positiveNum =\n  of(-2)\n    .map(x =\u003e x + 1)\n    .chain(x =\u003e typeof x === 'number'\n      ? of(x)\n      : Left(x))\n    .mapL(notNumber)\n    .logic({\n      cond: x =\u003e x \u003e 0,\n      pass: x =\u003e 'Positive number: ' + x,\n      fail: isNegative\n    })\n\npositiveNum.fold(x =\u003e console.log(x), x =\u003e console.error(x))\n\n// =\u003e Annotated Error: 'Negative number' -1\n\n```\n\nThe project is released under the [Mit License](./LICENSE)\n\n\n[npm-url]: https://www.npmjs.org/package/apropos\n[npm-image]: https://badge.fury.io/js/apropos.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzerobias%2Fapropos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzerobias%2Fapropos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzerobias%2Fapropos/lists"}