2.1.1 • Published 4 years ago

church v2.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

church

npm version Build Status

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

2.1.1

4 years ago

2.1.0

6 years ago

2.0.1

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago