Lambda functions and functional programming for javascript

## Installation

``````\$ npm install haskell
``````

## Lambda λ

Make functions out of lambda strings

``````f = require('haskell');

f('x*x')(5); // => 25

f('a b -> a+b')(1, 2); // => 3

f('+2')(f('+1')(1)); // => 4

greater_than_0 = f('>0');
greater_than_0(1); // => true
greater_than_0(-1); // => false

array = [-1, 0, 1, 2];
array.map('+1'); // => [0, 1, 2, 3]
array.filter('>0'); // => [1, 2]
array.map('+1').filter('>0'); => [1, 2, 3]
array.every('>0'); // => false
array.some('>0'); // => true

f.fold([1, 2, 3, 4], 'a+b'); // => 10

// reverse array
[1, 2, 3, 4].foldr('a b -> a.push(b)', []); // => [4, 3, 2, 1]

[1, 2, 3].map('+1').fold('a+b'); // => 9
``````

### .curry(fn, args...)

Curry a function with arguments. Returns a function with the arguments applied.

``````add3 = f('a + b + c')
// => 6

// => 4

// => 6

a = [-1, 0, 1, 2];
a.map(f('a+b').curry(2)); // f.map(a, f.curry('a+b', 2))
// => [1, 2, 3, 4]
``````

## Array functions

### .zip([array,] arrays...)

Zip multiple arrays into an array of arrays

``````[0, 1, 2, 3].zip([0, -1, -2, -3])
// => [[0, 0], [1, -1], [2, -2], [3, -3]]

Array.zip([1, 3, 5, 7], [2, 4, 6, 8])
// => [[1, 2], [3, 4], [5, 6], [7, 8]]

zip("and", "fish", "be")
// => [['a', 'f', 'b'], ['n', 'i', 'e']]
``````

### .unique([array])

Return an array of unique/distinct elements of an array

``````[1, 1, 2, 4, 5, 5, 5, 6, 7, 7].unique()
// => [1, 2, 4, 5, 6, 7]

Array.unique(["and", "fish", "be", "fish"])
// => ["and", "fish", "be"]

unique("array")
// => ['a', 'r', 'y']
``````

### .dictionary([array,] key)

Create a dictionary Object from an Array of objects

``````[
{ name: 'foo', value: 'bar' }
{ name: 'bar', value: 'baz' }
].dictionary('name')
// =>
// {
//   'foo': { name: 'foo', value: 'bar' }
//   'bar': { name: 'bar', value: 'baz' }
// }
``````

### .empty([array])

Verify if an array is empty

``````[1, 1, 2, 4, 5, 5, 5, 6, 7, 7].empty(); // => false

Array.empty([]); // => true

empty(""); // => true
``````

### .single([array])

Verify if an array is a single tuple

``````[1, 1, 2, 4, 5, 5, 5, 6, 7, 7].single(); // => false

Array.single([]); // => false

f.single([1]); // => true
``````

### .top([array])

Return the top element of an array

``````[1, 1, 2, 4, 5, 5, 5, 6, 6, 7].top(); // => 6

Array.top([]); // => undefined

``````

### .remove([array,] index/callback)

Remove items from an array by index or function test (affects original array)

``````[1, 1, 2, 4, 5, 5, 5, 6, 7, 7].remove(2)
// => [1, 1, 4, 5, 5, 5, 6, 7, 7]

Array.remove([1, 1, 2, 4, 5, 5, 5, 6, 7, 7], function(e) { return e == 5; })
// => [1, 1, 2, 4, 6, 7, 7]

remove([1], 0)
// => []
``````