{"id":21437414,"url":"https://github.com/keidrun/fantasy-utils","last_synced_at":"2025-09-09T06:43:34.790Z","repository":{"id":96381360,"uuid":"109671417","full_name":"keidrun/fantasy-utils","owner":"keidrun","description":"Small utils for Functional Programming with Promise.","archived":false,"fork":false,"pushed_at":"2017-11-27T05:16:36.000Z","size":181,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-23T09:41:56.625Z","etag":null,"topics":["functional","functional-programming","lodash","promise","promise-support","ramda"],"latest_commit_sha":null,"homepage":"","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/keidrun.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-06T09:04:41.000Z","updated_at":"2017-11-23T06:21:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"b603a0bb-bbad-4f81-9e9c-b4e1a6d46fa2","html_url":"https://github.com/keidrun/fantasy-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keidrun%2Ffantasy-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keidrun%2Ffantasy-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keidrun%2Ffantasy-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keidrun%2Ffantasy-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keidrun","download_url":"https://codeload.github.com/keidrun/fantasy-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243946270,"owners_count":20373020,"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":["functional","functional-programming","lodash","promise","promise-support","ramda"],"created_at":"2024-11-23T00:19:38.875Z","updated_at":"2025-03-16T23:25:20.707Z","avatar_url":"https://github.com/keidrun.png","language":"JavaScript","readme":"# fantasy-utils [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]\n\nSmall utils for Functional Programming.\n\n## Description\n\nThis provides small utilities to complement the lack of a functional library\nlike [ramda](https://github.com/ramda/ramda \"ramda\") or\n[lodash](https://github.com/lodash/lodash \"lodash\"). It includes both pure and\nimpure functions and fullfills an easy point-free style programming. Of course,\nall utilities are curried.\n\nAn example is below.\n\n```javascript\nconst R = require('ramda');\nconst F = require('fantasy-utils');\n\nconst dashrize = R.compose(\n  R.join('-'),\n  R.map(R.toLower),\n  F.trace('debug:'), // print middle data for debugging\n  R.split(' '),\n  R.replace(/\\s{2,}/gi, '')\n);\nconsole.log('result:', dashrize('Do you know our world is small?'));\n//=\u003e debug: [ 'Do', 'you', 'know', 'our', 'world', 'is', 'small?' ]\n//=\u003e result: do-you-know-our-world-is-small?\n```\n\nOther examples are below.\n\n```javascript\nconst R = require('ramda');\nconst F = require('fantasy-utils');\n\n// Promise way\nconst promiseDashrize = R.compose(\n  F.promiseBind(R.join('-')),\n  F.promiseBind(R.map(R.toLower)),\n  F.promiseBind(R.split(' ')),\n  F.promiseBind(R.replace(/\\s{2,}/gi, ''))\n);\npromiseDashrize(F.promiseOf('Do you know our limit is sky?'))\n  .then(console.log)\n  .catch(console.error);\n//=\u003e do-you-know-our-limit-is-sky?\n\n// Promise point-free style\nconst calc = R.compose(\n  F.promiseReduce((x, y) =\u003e x + y, 0),\n  F.promiseMap(x =\u003e x * 3),\n  F.promiseFilter(x =\u003e x % 2 === 0)\n);\ncalc(F.promiseOf([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))\n  .then(console.log)\n  .catch(console.error);\n//=\u003e 90\n```\n\n## Implementations\n\n### Pure functions\n\n* promiseOf :: Any -\u003e Promise Any\n* promiseBind :: (Function, Promise Any) -\u003e Promise Any\n* promiseMap :: (Function, Promise Array) -\u003e Promise Array\n* promiseFind :: (Function, Promise Array) -\u003e Promise Any\n* promiseFilter :: (Function, Promise Array) -\u003e Promise Array\n* promiseReduce :: (Function, Any, Promise Array) -\u003e Promise Any\n* promiseConcat :: (Array, Promise Array) -\u003e Promise Array\n* promiseSlice :: (Integer, Integer, Promise Array) -\u003e Promise Array\n* promiseSplice :: (Integer, Promise Array) -\u003e Promise Array\n\n### Impure functions\n\n* trace :: (String, Any) -\u003e Any\n\n[npm-url]: https://npmjs.org/package/fantasy-utils\n[npm-image]: https://badge.fury.io/js/fantasy-utils.svg\n[travis-url]: http://travis-ci.org/keidrun/fantasy-utils\n[travis-image]: https://secure.travis-ci.org/keidrun/fantasy-utils.svg?branch=master\n[depstat-url]: https://david-dm.org/keidrun/fantasy-utils\n[depstat-image]: https://david-dm.org/keidrun/fantasy-utils.svg\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeidrun%2Ffantasy-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeidrun%2Ffantasy-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeidrun%2Ffantasy-utils/lists"}