0.1.7 • Published 8 years ago

arrow.js v0.1.7

Weekly downloads
5
License
MIT
Repository
github
Last release
8 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

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.2.30

9 years ago

0.2.29

9 years ago

0.2.28

9 years ago

0.2.27

9 years ago

0.2.26

9 years ago

0.2.25

9 years ago

0.2.24

9 years ago

0.2.23

9 years ago

0.2.22

9 years ago

0.2.21

9 years ago

0.2.20

9 years ago

0.2.19

9 years ago

0.2.18

9 years ago

0.2.17

9 years ago

0.2.16

9 years ago

0.2.15

9 years ago

0.2.14

9 years ago

0.2.12

9 years ago

0.2.11

9 years ago

0.2.10

9 years ago

0.2.9

9 years ago

0.2.8

9 years ago

0.2.7

9 years ago

0.2.6

9 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago