var ramdaLite = require("./src/ramdaLite");
var multiplyByTwo = function (v) {
return v * 2;
};
var addTwo = function (v) {
return v + 2;
};
var addThree = function (v) {
return v + 3;
};
var composition = ramdaLite.compose(multiplyByTwo, addTwo, addThree);
composition(2)-- > 9;
- addTwo
- adjust
- all
- always
- and
- ap
- apply
- both
- binary
- bind
- complement
- compose
- contains
- defaultTo
- divide
- either
- empty
- false
- filter
- flip
- forEach
- gt
- gte
- has
- hasIn
- inc
- it
- juxt
- keys
- length
- last
- lte
- Maybe
- map
add two numbers together
var x = 5;
var y = 10;
ramdaLite.addTwo(x, y)-- > 15;
apply a function to a specific index in a list
var numbers = [4, 5, 6];
ramdaLite.adjust(5, 1, numbers)-- > [4, 10, 6];
a function that will return true if predicate is true for all values
var numbers = [4, 5, 6];
var isEven = function (val) {
return val % 2 === 0;
};
ramdaLite.all(isEven, list)-- > false;
a function that always returns true
ramdaLite.always()-- > true;
a function that returns true if both arguments are true
ramdaLite.and(true, false) --> false
a function that applies multiple methods to a list
var multiply = function (x) {
return x * 2;
};
var add = function (x) {
return x + 2;
};
ramdaLite.ap(multiply, add, [1, 2, 3]);
a function that applies a given context to a function to be invoked
ramdaLite.apply(console.log, 5) -> 5
a function that returns true if both functions passed to it with the argument are truthy
var isEven = function (value) {
return value % 2 === 0;
};
var greaterThanTwenty = function (value) {
return value > 20;
};
ramdaLite.both(isEven, greaterThanTwenty, 21);
a function that returns a function which only utilizes two arguments
var threeArgs = function (a, b, c) {
return [a, b, c];
};
var binaryArgsOnly = ramdaLite.binary(threeArgs);
binaryArgsOnly(1, 2, 3)-- > [1, 2, undefined];
a function that binds the this
context with the specified function and returns a bound function
var greet = function () {
return "hello " + this.name;
};
var obj = {
name: "theo",
};
var bound = ramdaLite.bind(greet, obj);
bound();
a function that returns a function which returns true if argument is identical to first function
var complement = ramdaLite.complement(null);
complement(null) -> true
complement(undefined) -> false
a function that can take an infinite amount of functions and call them sequentially on a value
var addTwo = function (v) {
return v + 2;
};
var multiplyByTwo = function (v) {
return v * 2;
};
var composition = ramdaLite.compose(addTwo, multiplyByTwo);
composition(2);
a function that returns true if value is in the supplied list
var numbers = [1,2,3,4];
var hasFour = ramdaLite.contains(4, numbers);
hasFour --> true
a function that divides two numbers
var x = 10;
var y = 5;
var quotient = ramdaLite.divide(x,y);
quotient --> 2
a function that returns true if value is truthy for one of two predicate functions
var value = 2;
var isOdd = function(v) {
return v % 3 === 0
}
var isEven = function(v) {
return v % 2 === 0
}
var either = ramdaLite.either(isEven, isOdd, value);
either --> true
a function that returns the JavaScript class representation of the supplied type as an empty type
var numbers = [1,2,3,4];
var value = ramdaLite.empty(numbers);
value --> []
a function that always returns false
var f = ramdaLite.false();
f --> false;
a function that filters a list based of the the predicate function
var numbers = [1,2,3,4];
var filtered = ramdaLite.filter(numbers, function(v) {
return v % 2 === 0
});
filtered --> [2,4]
a function that reverses argument order of functions
var multiply = function(x) {
return x * 2
}
var add = function(x) {
return x + 2
}
var flipped = ramdaLite.flipped(multiply, add);
flipped(4) --> add --> multiply --> 12
a function that will iterate through a list and call a function on each value in the list
var list = [1,2,3,4];
var log = function(v) {
console.log('value is ' + v)
}
ramdaLite.forEach(log, list) -> 'The value is 1', 'The value is 2', 'The value is 3', 'The value is 4'
a function that returns true if the first argument is greater than the second argument
var x = 5;
var y = 10;
var result = ramdaLite.gt(x,y);
result --> false;
a function that returns true if the first argument is greater than or equal to the second argument
var x = 10;
var y = 10;
var result = ramdaLite.gte(x,y);
result --> true
a function that takes in a value and return the value as its self.
var value = 10;
var result = ramdaLite.identity(10);
result --> 10;
a function that will take in a value and increment it by 1
var result = ramdaLite.inc(5);
result --> 6
a function that will return true if first argument is an instance of the second argumet (its constructor)
var obj = {
name: 'theo'
};
var result = ramdaLite.is(obj, {}) --> true
var falsy = ramdaLite.is(obj, []) --> false
a function that returns true if the first argument is less than the second argument
var x = 5;
var y = 10;
ramdaLite.it(x,y) --> true
a function that will return true if the value is empty
var value = [1,2,3];
var value2 = [];
ramdaLite.isEmpty(value) -> false;
ramdaLite.isEmpty(value2) -> true;
a function which is invokes multiple functions on a list of values
var double = function(x) {
return x * x
}
var addThree = function(x) {
return x + 3
}
var list = [1,2,3,4];
var result = ramdaLite.juxt(double,triple,list);
result --> [4,7,12,19]
a function that creates a new array from an Object
with just the keys
var obj = {
name: 'theo',
height: 69,
age: 23
};
ramdaLite.keys(obj) -> ['name', 'height', 'age']
a function that returns the length of a list
var numbers = [1,2,3,4];
ramdaLite.length(numbers) --> 4
a function that returns the last element in an Array
var numbers = [1,2,3,4];
ramdaLite.last(numbers) --> 4;
a function that returns true if the first argument is less than or equal to the second argument
var x = 5;
var y = 10;
ramdaLite.lte(5,10) --> true;
a function that takes a value and wraps it an an Array
container with either an error or the value
var good = 5;
var bad = null;
ramdaLite.Maybe(good) --> [5]
ramdaLite.Maybe(bad) --> ['error']
a function that takes a list and a function to apply to each value in the list. returns a new Array
var numbers = [1,2,3,4];
var double = function(v) {
return v * 2
}
ramdaLite.map(numbers, double) --> [2,4,6,8];
a function that takes a list and returns the maximum value
var numbers = [2,34,100,9];
ramdaLite.max(numbers) --> 100
a function that returns a cached value of the passed in function if it has already been stored
var multiplyByTwo = function(v) {
return v * 2
}
var memoize = ramdaLite.memoize(multiplyByTwo);
memoize(multiplyByTwo(2)) -> returns function from cache
memoize(console.log(2)) -> adds method to cache and returns console.log(2)
a function that takes a list and returns the minimum value
var numbers = [1,2,3,4];
ramdaLite.min(numbers) --> 1