{"id":21923437,"url":"https://github.com/f0rr0/church-encoding","last_synced_at":"2025-09-01T06:33:19.510Z","repository":{"id":93471351,"uuid":"127582311","full_name":"f0rr0/church-encoding","owner":"f0rr0","description":"⛪ Church encodings for JavaScript primitives","archived":false,"fork":false,"pushed_at":"2020-06-02T18:13:02.000Z","size":1911,"stargazers_count":4,"open_issues_count":19,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-30T00:38:40.654Z","etag":null,"topics":["church-encoding","combinatory-logic","functional-programming","lambda-calculus"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/f0rr0.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2018-04-01T00:25:49.000Z","updated_at":"2024-01-31T22:33:10.000Z","dependencies_parsed_at":"2023-03-08T03:15:30.902Z","dependency_job_id":null,"html_url":"https://github.com/f0rr0/church-encoding","commit_stats":{"total_commits":42,"total_committers":3,"mean_commits":14.0,"dds":0.1428571428571429,"last_synced_commit":"4d8de7153d35ff7fd576a466b7c6925740feb5df"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/f0rr0/church-encoding","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f0rr0%2Fchurch-encoding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f0rr0%2Fchurch-encoding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f0rr0%2Fchurch-encoding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f0rr0%2Fchurch-encoding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f0rr0","download_url":"https://codeload.github.com/f0rr0/church-encoding/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f0rr0%2Fchurch-encoding/sbom","scorecard":{"id":389444,"data":{"date":"2025-08-11","repo":{"name":"github.com/f0rr0/church-encoding","commit":"4d8de7153d35ff7fd576a466b7c6925740feb5df"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/27 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: Do What The F*ck You Want To Public License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 8 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"92 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-6chw-6frg-f759","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx","Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-mh2h-6j8q-x246","Warn: Project is vulnerable to: GHSA-5q88-cjfq-g2mh","Warn: Project is vulnerable to: GHSA-xp63-6vf5-xf3v","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-rq8g-5pc5-wrhr","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-hr2v-3952-633q","Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm","Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c","Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6","Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9","Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f","Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p","Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv","Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8","Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65","Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq","Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm","Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-pc5p-h8pf-mvwp","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546","Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574","Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-xf5p-87ch-gxw2","Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj","Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf","Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3","Warn: Project is vulnerable to: GHSA-f9cm-qmx5-m98h","Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9","Warn: Project is vulnerable to: GHSA-w7rc-rwvf-8q5r","Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-4p35-cfcx-8653","Warn: Project is vulnerable to: GHSA-7f3x-x4pr-wqhj","Warn: Project is vulnerable to: GHSA-jpp7-7chh-cf67","Warn: Project is vulnerable to: GHSA-q6wq-5p59-983w","Warn: Project is vulnerable to: GHSA-j9fq-vwqv-2fm2","Warn: Project is vulnerable to: GHSA-pqw5-jmp5-px4v","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-r2j6-p67h-q639","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp","Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr","Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7","Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v","Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T17:27:41.941Z","repository_id":93471351,"created_at":"2025-08-18T17:27:41.941Z","updated_at":"2025-08-18T17:27:41.941Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273082410,"owners_count":25042282,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["church-encoding","combinatory-logic","functional-programming","lambda-calculus"],"created_at":"2024-11-28T21:11:39.855Z","updated_at":"2025-09-01T06:33:19.461Z","avatar_url":"https://github.com/f0rr0.png","language":"JavaScript","readme":"\u003ch3 align=\"center\"\u003e\n  \u003cimg align=\"center\" src=\"assets/church.png\" alt=\"Church logo\" width=200\n  /\u003e\n\u003c/h3\u003e\n\u003cp align=\"center\"\u003e\nChurch encodings for JavaScript primitives\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.org/f0rr0/church-encoding\"\u003e\n    \u003cimg\n      src=\"https://travis-ci.org/f0rr0/church-encoding.svg?branch=master\"\n      alt=\"travis\"\n      height=\"20\"\n    \u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/f0rr0/church-encoding\"\u003e\n    \u003cimg\n      src=\"https://codecov.io/gh/f0rr0/church-encoding/branch/master/graph/badge.svg\"\n      alt=\"codecov\"\n      height=\"20\"\n    \u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@f0rr0/church-encoding\"\u003e\n    \u003cimg\n      src=\"https://img.shields.io/npm/v/@f0rr0/church-encoding.svg?style=flat\"\n      alt=\"npm version\"\n      height=\"20\"\n    \u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://david-dm.org/f0rr0/church-encoding\"\u003e\n    \u003cimg\n      src=\"https://david-dm.org/f0rr0/church-encoding/status.svg?style=flat\"\n      alt=\"dependencies\"\n      height=\"20\"\n    \u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://david-dm.org/f0rr0/church-encoding?type=dev\"\u003e\n    \u003cimg\n      src=\"https://david-dm.org/f0rr0/church-encoding/dev-status.svg?style=flat\"\n      alt=\"dev dependencies\"\n      height=\"20\"\n    \u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/semantic-release/semantic-release\"\u003e\n    \u003cimg\n      src=\"https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat\"\n      alt=\"semantic-release\"\n      height=\"20\"\n    \u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/prettier/prettier\"\u003e\n    \u003cimg\n      src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat\"\n      alt=\"code style: prettier\"\n      height=\"20\"\n    \u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://greenkeeper.io/\"\u003e\n    \u003cimg\n      src=\"https://badges.greenkeeper.io/f0rr0/church-encoding.svg?style=flat\"\n      alt=\"Greenkeeper badge\"\n    \u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n# church-encoding\n[Wikipedia Page](https://en.wikipedia.org/wiki/Church_encoding). This is a thought exercise in functional programming to represent most of the javascript primitives using only lambdas (anonymous functions). It's not intended to be used in any production user facing software.\n\n## Motivation\n\nI was informally introduced to this idea by watching [this talk](https://www.youtube.com/watch?v=XrNdvWqxBvA) by [John Hughes](http://www.cse.chalmers.se/~rjmh/) which is based on [his paper](https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf). [This talk](https://www.youtube.com/watch?v=IOiZatlZtGU) by [Philip Walder](http://homepages.inf.ed.ac.uk/wadler/) brilliantly explains this in a more historical context. The [SICP book](https://mitpress.mit.edu/sicp/full-text/book/book.html) also introduced me to using lambdas and recursive constructs to define operations on lists. There are many more comprehensive implementations in typed functional languages but I wanted to see how far I could go without a formal type system and combinators. Ultimately, on a more philosophical note, this exercise sufficiently proves that:\n\n\u003e Mathematics is not invented. It is discovered.\n\n## Install\n\n```\nnpm install @f0rr0/church-encoding@latest\n```\nor if you're using `yarn`\n```\nyarn add @f0rr0/church-encoding@latest\n```\n\n## Usage\nThere are 3 different builds in `commonjs`, `umd` and `esmodule` format, should you have a preference or environment constraints. Normally, modern tools will automatically pick the `esmodule` build which enables tree-shaking.\n```js\n  import {\n    cons,\n    emptyList,\n    zero,\n    inc,\n    map,\n    mul,\n    decodeInteger,\n    decodeList\n  } from '@f0rr0/church-encoding';\n\n  const one = inc(zero);\n  const two = inc(one);\n  const list = cons(zero, cons(one, cons(two, emptyList)));\n\n  console.log(decodeList(map(decodeInteger, list))); // [0, 1, 2]\n\n  const doubleList = map(i =\u003e mul(two, i), list);\n\n  console.log(decodeList(map(decodeInteger, doubleList))); // [0, 2, 4]\n```\n## API\n\nThe API is organized into five parts which progressively build on each other. However, since everything is a function, they are not namespaced into separate exports. The function names pretty much sum up what they do.\n\n1.  [Boolean](#boolean)\n2.  [List](#list)\n3.  [Natural Number](#natural-number)\n4.  [Integer](#integer)\n5.  [Decode](#decode)\n\n### Boolean\n\n* T\n* F\n* IF\n* AND\n* OR\n* NOT\n\n### List\n\n* emptyList\n* cons\n* head\n* tail\n* isEmpty\n* map\n* filter\n* nth\n* length\n\n### Natural Number\n\n* zeroNat\n* isZeroNat\n* incNat\n* decNat\n* addNat\n* subNat\n* isEqualNat\n* mulNat\n* expNat\n* isLessThanNat\n* isLessThanEqualNat\n* isGreaterThanNat\n* isGreaterThanEqualNat\n* divNat\n* modNat\n\n### Integer\n\n* pair\n* first\n* second\n* zero\n* isZero\n* inc\n* dec\n* normalize\n* abs\n* negate\n* add\n* sub\n* isEqual\n* mul\n* exp\n* isNegative\n* isLessThan\n* isLessThanEqual\n* isGreaterThan\n* isGreaterThanEqual\n\n### Decode\n\n* decodeBool\n* decodeList\n* decodeNat\n* decodeInteger\n\n### Limitations\n\nI still have to work on implementing rational numbers so that integer division can work. There are no `throw` or `Error` statements in the codebase since I strived to only use lambdas. Therefore, you need to be careful to not do mathematically impossible stuff e.g. divide a natural number by `zeroNat`, or else you'd be presented with a cryptic error.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff0rr0%2Fchurch-encoding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff0rr0%2Fchurch-encoding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff0rr0%2Fchurch-encoding/lists"}