{"id":17446001,"url":"https://github.com/jamen/esfp","last_synced_at":"2025-09-25T01:31:00.887Z","repository":{"id":57227563,"uuid":"90667042","full_name":"jamen/esfp","owner":"jamen","description":"(Archived) Improve functional programming in JavaScript","archived":false,"fork":false,"pushed_at":"2017-05-17T02:51:18.000Z","size":20,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-12T11:43:39.125Z","etag":null,"topics":[],"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/jamen.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":"2017-05-08T19:54:49.000Z","updated_at":"2021-12-19T15:36:51.000Z","dependencies_parsed_at":"2022-09-12T17:00:24.187Z","dependency_job_id":null,"html_url":"https://github.com/jamen/esfp","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fesfp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fesfp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fesfp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fesfp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamen","download_url":"https://codeload.github.com/jamen/esfp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234143357,"owners_count":18786140,"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-10-17T18:20:01.599Z","updated_at":"2025-09-25T01:31:00.590Z","avatar_url":"https://github.com/jamen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# ES Functional Programming\n\n\u003e Improve functional programming in JavaScript\n\nThis is a [Browserify transform](https://www.npmjs.com/package/browserify) with several features (some non-standard) to improve writing JavaScript in a functional style. This repo also serves as a place to discuss moving JavaScript in a more functional direction, and how to impliment that here.\n\n## Features\n\n - The good ES6+ features (inspired from [`es2020`](https://npmjs.com/es2020) and [`es2040`](https://npmjs.com/es2040))\n   - Template literals\n   - Arrow functions\n   - Block scoping\n   - Destructuring\n   - Default params\n   - Rest/spread\n   - Shorthand properties (e.g. `{ foo, bar }`)\n   - Object rest/spreads (e.g. `{ ...foo, bar: 123 }`)\n - Non-standard features\n   - [Pipe operator over](https://npmjs.com/babel-plugin-pull) [`pull-stream`](https://github.com/pull-stream/pull-stream)\n   - [Implicit return value](https://npmjs.com/babel-plugin-implicit-return)\n   - React JSX with `pragma: 'h'` out-of-the-box\n   - [Static type checking with Flow](https://flow.org/)\n\nHere is an example of piping, with implicit return, and cloning an object using spread:\n\n```js\nfunction foo (options) {\n  options = { bar: 123, ...options }\n\n  foobar(options)\n  | bazqux()\n  | oofrab()\n}\n```\n\n## Install\n\n```sh\nnpm install --save esfp\n\n# with yarn\nyarn add esfp\n```\n\n## Usage\n\nLoad as a browserify transform in whatever tool you use.  For example, with CLI:\n\n```js\nbrowserify entry.js -g esfp \u003e out.js\n```\n\nOr with `browserify`\n\n```js\nb.transform('esfp')\n```\n\nOr [`pull-bundle`](https://npmjs.com/pull-bundle) (for a more functional solution :wink:)\n\n```js\nbundle('app.js', [ 'esfp' ])\n```\n\n### Pipe operator\n\nTo use the pipe operator, you should first be familiar with [`pull-stream`](https://github.com/pull-stream/pull-stream), as it will let you do cool things like async and partial pipelines.\n\nHere we just transform `foo | bar | ...` chains into `pull(foo, bar, ...)` calls:\n\n```js\nvalues([1, 2, 3])\n| map(x =\u003e x * 3)\n| drain(console.log)\n\n// into:\n\npull(\n  values([1, 2, 3])\n  map(x =\u003e x * 3),\n  drain(console.log)\n)\n```\n\nYou can also create streams from other streams (known as a \"partial\"):\n\n```js\nconst foo =\n  infinity()\n  | map(x =\u003e x * 100)\n  | filter(x =\u003e x % 2)\n\n// Use it in another pipeline:\nfoo | drain(console.log)\n```\n\nSee [`babel-plugin-pull`](https://npmjs.com/babel-plugin-pull) for more details\n\n### Implicit return value\n\nYou don't need to return the last value in a function:\n\n```js\nfunction foo (x) {\n  x % 1 !== 0\n}\n```\n\nThis is especially useful in combination with the pipe operator and partial streams:\n\n```js\nfunction foo ({ modifier }) {\n  values([ 1, 2, 3 ])\n  | map(x =\u003e x * modifier)\n}\n\nfoo({ modifier: 3 })\n| drain(console.log)\n```\n\nSee [`babel-plugin-implicit-return`](https://npmjs.com/babel-plugin-implicit-return) for more details\n\n### JSX pragma `h`\n\nWith [`transform-react-jsx`](https://npmjs.com/babel-plugin-transform-react-jsx) + `pragma: 'h'` you have more high-level sytnax creating views with functions.\n\n```js\nfunction foo (e, data) {\n  \u003cdiv onclick=${e}\u003e${data}\u003c/div\u003e\n}\n```\n\nYou can use this with librares like [`hyperapp`](https://npmjs.com/hyperapp) instead of having to load `babelify` + the plugin.\n\n\n### Static type checking\n\nThis plugin automatically strips [Flow types](https://flow.org/) for static type checking.\n\n**Note:** It does not actually check the types. Use something like [ESLint](https://github.com/gajus/eslint-plugin-flowtype) for that aspect.\n\n```js\nfunction foo (bar: number, baz: number): number {\n  return bar + baz\n}\n```\n\nThis could be replaced with a more functional-style type checking:\n\n```js\n// foo : number, number\nfunction foo (bar, baz) {\n  return bar + baz\n}\n```\n\nLet me know your suggestions\n\n---\n\nMaintained by [Jamen Marz](https://git.io/jamen) (See on [Twitter](https://twitter.com/jamenmarz) and [GitHub](https://github.com/jamen) for questions \u0026 updates)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamen%2Fesfp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamen%2Fesfp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamen%2Fesfp/lists"}