{"id":21364837,"url":"https://github.com/fbn/futurity","last_synced_at":"2025-07-13T04:31:17.929Z","repository":{"id":57243376,"uuid":"340972996","full_name":"FbN/futurity","owner":"FbN","description":"Swiss Army Knife Fluture Based Data Structure","archived":false,"fork":false,"pushed_at":"2021-02-24T12:51:08.000Z","size":409,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-14T00:39:50.222Z","etag":null,"topics":[],"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/FbN.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":"2021-02-21T18:26:26.000Z","updated_at":"2021-05-11T21:27:42.000Z","dependencies_parsed_at":"2022-09-15T09:01:29.396Z","dependency_job_id":null,"html_url":"https://github.com/FbN/futurity","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/FbN%2Ffuturity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FbN%2Ffuturity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FbN%2Ffuturity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FbN%2Ffuturity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FbN","download_url":"https://codeload.github.com/FbN/futurity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225855970,"owners_count":17534967,"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-22T07:07:56.546Z","updated_at":"2024-11-22T07:07:57.223Z","avatar_url":"https://github.com/FbN.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/FbN/futurity\"\u003e\n    \u003cimg src=\"images/logo.png\" alt=\"FUTURITY\" width=\"400\"\u003e\n  \u003c/a\u003e\n\n  \u003ch3 align=\"center\"\u003eSwiss Army Knife \u003cstrong\u003eFluture Based\u003c/strong\u003e Data Structure\u003c/h3\u003e\n\n  \u003cp align=\"center\"\u003e\n    Powered by\n    \u003ca href=\"https://github.com/fluture-js/Fluture\"\u003e\n        \u003cimg src=\"https://github.com/fluture-js/Fluture/raw/master/logo.png\" alt=\"Fluture\" height=\"40\" style=\"vertical-align: baseline\"/\u003e\n    \u003c/a\u003e\n  \u003c/p\u003e\n\n  \u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/fantasyland/fantasy-land\"\u003e\n        \u003cimg src=\"https://github.com/fantasyland/fantasy-land/raw/master/logo.png\" alt=\"Fluture\" height=\"40\" style=\"vertical-align: baseline\"/\u003e\n    \u003c/a\u003e\n    Implements Fantasy Land:\u003cbr /\u003e\u003cstrong\u003eFunctor\u003c/strong\u003e, \u003cstrong\u003eBifunctor\u003c/strong\u003e,\n    \u003cstrong\u003eApply\u003c/strong\u003e, \u003cstrong\u003eApplicative\u003c/strong\u003e, \u003cstrong\u003eChain\u003c/strong\u003e,\n    \u003cstrong\u003eMonad\u003c/strong\u003e\n  \u003c/p\u003e\n\u003c/p\u003e\n\n\n\n\u003c!-- TABLE OF CONTENTS --\u003e\n## Table of Contents\n\n* [About the Project](#about-the-project)\n  * [Built With](#built-with)\n* [Getting Started](#getting-started)\n  * [Installation](#installation)\n* [Usage](#usage)\n* [API Documentation](#API)\n* [License](#license)\n* [Contact](#contact)\n\n\n\u003c!-- ABOUT THE PROJECT --\u003e\n## About The Project\n\nThis data structure is a wrapper for reuse everyday mutable and effectfull promise based libs in a functional monadic future based fashion.\n\nIf Fluture moand wraps a computation that async resolve to a value, Futurity brigs tree data structures:\n* Reader e -\u003e a : [Reader monad](https://github.com/monet/monet.js/blob/master/docs/READER.md) used to lazy wrap a mutable effectfull lib (like knex or superagent for example).\n\n    \u003e Is a lazy Product Type that enables the composition of computations that depend on a shared \u003e environment (e -\u003e a). The left portion, the e must be fixed to a type for all related computations. The right portion a can vary in its type.\n    -- \u003ccite\u003e[Crocks Dev](https://crocks.dev/docs/crocks/Reader.html)\u003c/cite\u003e\n\n* e -\u003e e : Environment reducer function, used to transforms environment before run it in the computation Reader.\n\n* Reader a -\u003e Future b : A lazy structure (another Reader Monad) that takes the result value of the collapsing of first reader monad as environment and return a Future instance.\nAll fluture operators (map, chain, ap...) applied to the data structure transforms the yet to exists future instace wrapped by the this monad.\n\n### Built With\nFuturity is implemented in a few lines of code that mix up some good libraries:\n* [Fluture](https://github.com/fluture-js/Fluture)\n* [Monet.js](https://monet.github.io/monet.js/)\n\n\u003c!-- GETTING STARTED --\u003e\n## Getting Started\n\n### Installation\n\n1. Add Futurity to your project\n\n  ```sh\n  yarn add futurity\n  ```\n2. If not already in your project add peer dependencies\n\n    ```sh\n    yarn add fluture\n    ```\n\n\u003c!-- USAGE EXAMPLES --\u003e\n## Usage\n\nYou can look in tests for other examples.\n\nSample of knex wrapping.\n\n```js\nimport Knex from 'knex'\nimport { Futurity, coMap, envMap } from 'futurity'\nimport * as F from 'fluture'\n\nconst I = a =\u003e a\nconst pipe = (...args) =\u003e args.reduce((f, g) =\u003e x =\u003e g(f(x)))\n\nconst db = Knex({\n    client: 'sqlite3',\n    connection: {\n        filename: 'tests/chinook.sqlite'\n    },\n    useNullAsDefault: true\n})\n\n// Futurity that wrap knex instance\nconst DbFuturity = (db, args) =\u003e\n    Futurity.lift(\n        p =\u003e db(...args),\n        qb =\u003e F.attemptP(() =\u003e qb)\n    )\n\nconst query = pipe(\n    coMap(qb =\u003e qb.where({ Composer: 'Nirvana' })),\n    coMap(qb =\u003e qb.limit(2)),\n    F.map(rows =\u003e rows.map(track =\u003e track.Name))\n)(DbFuturity(db, ['Track']))\n\n(async function(){\n    const value = await F.promise(query)\n    console.log(value)\n})()\n```\n\nOutput:\n```js\n['Aneurysm', 'Smells Like Teen Spirit']\n```\nSample of superagent wrapping\n```js\nimport request from 'superagent'\nimport { Futurity, coMap, envMap } from 'futurity'\nimport * as F from 'fluture'\n\nconst I = a =\u003e a\nconst pipe = (...args) =\u003e args.reduce((f, g) =\u003e x =\u003e g(f(x)))\n\n// Futurity that wrap Superagent instance\nconst SaFuturity = method =\u003e\n    Futurity.lift(request[method], agent =\u003e F.attemptP(() =\u003e agent))\n\nconst query = pipe(\n    envMap(() =\u003e 'https://jsonplaceholder.typicode.com/todos/1'),\n    F.map(res =\u003e res.body),\n    F.map(body =\u003e body.title),\n    coMap(req =\u003e req.set('accept', 'json'))\n)(SaFuturity('get'))\n\n(async function(){\n    const title = await F.promise(query)\n    console.log(title)\n})()\n```\n\nOutput:\n```js\n'delectus aut autem'\n```\n\n\n\u003c!-- ROADMAP --\u003e\n## API\n\nThe data structure is a Fluture extension (so you can directly use all [Fluture operators and API]([Knex](http://knexjs.org/))).\n\nException for cache and hooks not yet implemented (but you can collapse a Futurity instance to a Fluture instance at you occorence).\n\nIn addition to standard Fluture functions we have:\n\n### Factories\n- [`lift`](#lift)\n\n### Operators\n- [`envMap`](#envMap)\n- [`coMap`](#coMap)\n\n### Consuming / Collapsing Operators\n- [`future`](#future)\n\n## Factories\n\n### \u003ca id=\"lift\"\u003e\u003c/a\u003e `lift(computation: e -\u003e a, computationToFuture: a -\u003e Future b)`\n\nContruct a new Futurity Instance, environment is intialized to identity function.\n\n#### Arguments:\n\n- `computation: e -\u003e a` Function that takes the environment and return the target value.\n\n- `computationToFuture: a -\u003e Future b` Function that takes the computation result and transform it to a future.\n\nReturns:  **Futurity Instance**\n\n## Operators\n\n### \u003ca id=\"envMap\"\u003e\u003c/a\u003e `envMap(e -\u003e e)`\n\nEnvironment reducer. Function to transform the initial environment.\n\n#### Arguments:\n\n- `pred: e -\u003e e` Function that has the current environment as input and return the new environment.\n\nReturns:  **Futurity Instance**\n- - -\n\n### \u003ca id=\"coMap\"\u003e\u003c/a\u003e `coMap((a, e) -\u003e a)`\n\nFunction to transform the wrapped effectfull object.\n\n#### Arguments:\n\n- `(a, e) -\u003e a` For your confort the environment is passed as second argumet so you can you it.\n\nReturns:  **Futurity Instance**\n- - -\n\n## Consuming / Collapsing Operators\n\n### \u003ca id=\"future\"\u003e\u003c/a\u003e `future(fty)`\n\nMake the futurity instance collapse to a Future instance (not yet resolved).\n\n#### Arguments:\n\n- `fty` Futurity instance.\n\nReturns:  **Future Instance**\n- - -\n\u003c!-- LICENSE --\u003e\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n\n\u003c!-- CONTACT --\u003e\n## Contact\n\nFabiano Taioli - ftaioli@gmail.com\n\nProject Link: [https://github.com/FbN/futurity](https://github.com/FbN/futurity)\n\n\n\u003c!-- MARKDOWN LINKS \u0026 IMAGES --\u003e\n\u003c!-- https://www.markdownguide.org/basic-syntax/#reference-style-links --\u003e\n[contributors-shield]: https://img.shields.io/github/contributors/FbN/futurity.svg?style=flat-square\n[contributors-url]: https://github.com/FbN/futurity/graphs/contributors\n[forks-shield]: https://img.shields.io/github/forks/FbN/futurity.svg?style=flat-square\n[forks-url]: https://github.com/FbN/futurity/network/members\n[stars-shield]: https://img.shields.io/github/stars/FbN/futurity.svg?style=flat-square\n[stars-url]: https://github.com/FbN/futurity/stargazers\n[issues-shield]: https://img.shields.io/github/issues/FbN/futurity.svg?style=flat-square\n[issues-url]: https://github.com/FbN/futurity/issues\n[license-shield]: https://img.shields.io/github/license/FbN/futurity.svg?style=flat-square\n[license-url]: https://github.com/FbN/futurity/blob/master/LICENSE.txt\n[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square\u0026logo=linkedin\u0026colorB=555\n[linkedin-url]: https://linkedin.com/in/fabiano-taioli-42917723\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffbn%2Ffuturity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffbn%2Ffuturity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffbn%2Ffuturity/lists"}