GithubHelp home page GithubHelp logo

classicvalues / church Goto Github PK

View Code? Open in Web Editor NEW

This project forked from benji6/church

1.0 1.0 0.0 771 KB

:church: Church Encoding in JS

Home Page: http://benji6.github.io/church/docs

License: MIT License

JavaScript 100.00%

church's Introduction

church

npm version CI

Church encoding utility library for JavaScript

Why?

I built this library mostly as a learning exercise, but the code is also available as an npm module that can be consumed and used to build JavaScript applications using basically nothing but functions. I'm not sure why you would want to do that though!

What?

Church encoding is a way of encoding data using only functions. For instance, we can use functions to represent, booleans, numerals and lists. Higher-order functions are all you need for Turing completeness.

How?

Check out the docs.

Install

npm i church or yarn add church.

Examples

import {
  decodeList,
  decodeNumeral,
  encodeList,
  encodeNumeral,
  five,
  If,
  lt,
  map,
  mult,
  one,
  range,
  three,
  two,
} from 'church'

const twoFourSix = map(mult(two))(range(one)(three))
// => Church encoded list of [two four six]

const twoFourSixJs = decodeList(twoFourSix).map(decodeNumeral)
// => [2, 4, 6] (standard JS array of standard JS numbers)

encodeList(twoFourSixJs.map(encodeNumeral))
// => Church encoded list of [two four six] again

map(x => If(lt(x)(five))(five)(x))(twoFourSix)
// => Church encoded list of [five five six]

Resources

church's People

Contributors

dependabot-preview[bot] avatar benji6 avatar dependabot[bot] avatar

Stargazers

Classic Values avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.