0.1.7 • Published 9 years ago

arrow.js v0.1.7

Weekly downloads
5
License
MIT
Repository
github
Last release
9 years ago

arrowjs

John Hughes' arrows.

Usage

  • Arrow(f)

Given an function, it creates an arrow.

function inc(val) {
  return v + 1;
}

Arrow(inc).run(1) == 2;
  • Arrow.next(arrA, arrB)

Compose two arrows.

function inc(v) {
  return v + 1;
}

function decr(v) {
  return v - 1;
}

Arrow(inc).next(Arrow(decr)).run(1) == Arrow.next(Arrow(inc), Arrow(decr)).run(1);
  • Arrow.first(arr)

Given a tuple, it will run the arrow with the first element of the tuple.

function inc(v) {
  return v + 1;
}

Arrow(inc).first().run({_1: 10, _2: 4}) == {_1: 11, _2: 4};
Arrow.first(Arr(inc)).run({_1: 10, _2: 4}) == {_1: 11, _2: 4};
  • Arrow.second(arr)

Given a tuple, it will run the arrow with the second element of the tuple.

function inc(v) {
  return v + 1;
}

Arrow(inc).second().run({_1: 10, _2: 4}) == {_1: 10, _2: 5};
Arrow.secondfirst(Arr(inc)).run({_1: 10, _2: 4}) == {_1: 10, _2: 5};
  • Arrow.bifur(arrA, arrB)

Given two arrows, apply each arrow to a value and return a tuple.

function inc(v) {
  return v + 1;
}

function decr(v) {
  return v - 1;
}

Arrow.bifur(Arrow(inc), Arrow(decr)).run(5) == {_1: 6, _2: 4};
  • Arrow.prod(arrA, arrB)

Given two arrows, returns an arrow that receives a tuple and apply each one to the correpondent in the tuple.

function inc(v) {
  return v + 1;
}

function decr(v) {
  return v - 1;
}

Arrow.prod(Arrow(inc), Arrow(decr)).run({_1: 6, _2: 4}) == {_1: 7, _2: 3};
0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.2.30

10 years ago

0.2.29

10 years ago

0.2.28

10 years ago

0.2.27

10 years ago

0.2.26

10 years ago

0.2.25

10 years ago

0.2.24

10 years ago

0.2.23

10 years ago

0.2.22

10 years ago

0.2.21

10 years ago

0.2.20

10 years ago

0.2.19

10 years ago

0.2.18

10 years ago

0.2.17

10 years ago

0.2.16

10 years ago

0.2.15

10 years ago

0.2.14

10 years ago

0.2.12

10 years ago

0.2.11

10 years ago

0.2.10

10 years ago

0.2.9

10 years ago

0.2.8

10 years ago

0.2.7

10 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago