R.reduceRight
Added in v0.1.0
(a, b -> b) -> b -> [a] -> b
see R.reduce
R.reduceRight(R.subtract, 0, {1, 2, 3, 4}) --> (1 - (2 - (3 - (4 - 0)))) = -2
-- - -2
-- / \ / \
-- 1 - 1 3
-- / \ / \
-- 2 - ==> 2 -1
-- / \ / \
-- 3 - 3 4
-- / \ / \
-- 4 0 4 0
R.adjust Array
Added in v0.1.0
(a -> a) -> Number -> [a] -> [a]
see R.update
R.adjust(R.add(10), 2, {1, 2, 3}) --> {1, 12, 3}
R.adjust(R.add(10))(2)({1, 2, 3}) --> {1, 12, 3}
R.all Array
Added in v0.1.0
(a -> Boolean) -> [a] -> Boolean
local equals3 = R.equals(3)
R.all(equals3, {3, 3, 3, 3}) --> true
R.all(equals3)({3, 3, 1, 3}) --> false
R.any Array
Added in v0.1.0
(a -> Boolean) -> [a] -> Boolean
local lessThan0 = R.lt(R.__, 0)
local lessThan2 = R.lt(R.__, 2)
R.any(lessThan0, {1, 2}) --> false
R.any(lessThan2)({1, 2}) --> true
R.aperture Array
Added in v0.1.0
Number -> [a] -> [ [a] ]
R.aperture(2, {1, 2, 3, 4, 5}) --> {{1, 2}, {2, 3}, {3, 4}, {4, 5}}
R.aperture(3, {1, 2, 3, 4, 5}) --> {{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}
R.aperture(7, {1, 2, 3, 4, 5}) --> {}
R.aperture(0, {1, 2, 3, 4, 5}) --> {{}, {}, {}, {}, {}, {}}
R.append Array
Added in v0.1.0
a -> [a] -> [a]
see R.prepend
R.append('tests', {'write', 'more'}) --> {'write', 'more', 'tests'}
R.append('tests', {}) --> {'tests'}
R.append({'tests'}, {'write', 'more'}) --> {'write', 'more', {'tests'}}
R.assoc Array
Added in v0.1.0
String -> a -> {k: v} -> {k: v}
see R.dissoc
R.assoc('c', 3, {a = 1, b = 2}) --> {a = 1, b = 2, c = 3}
R.assocPath Array
Added in v0.1.0
[Idx] -> a -> {a} -> {a}
see R.dissocPath
R.assocPath({'a', 'b', 'c'}, 42, {a = {b = {c = 0}}}) --> {a = {b = {c = 42}}}
-- Any missing or non-object keys in path will be overridden
R.assocPath({'a', 'b', 'c'}, 42, {a = 5}) --> {a = {b = {c = 42}}}
R.chain Array
Added in v0.1.0
Chain m => (a -> m b) -> m a -> m b
local duplicate = function(n) return {n, n} end
R.chain(duplicate, {1, 2, 3}) --> {1, 1, 2, 2, 3, 3}
R.chain(R.append, R.head)({1, 2, 3}) --> {1, 2, 3, 1}
R.concat Array
Added in v0.1.0
String -> String -> String
R.concat('ABC', 'DEF') --> 'ABCDEF'
R.concat([4, 5, 6], [1, 2, 3]) --> [4, 5, 6, 1, 2, 3]
R.concat([], []) --> []
R.contains Array
Added in v0.1.0
a -> [a] -> Boolean
see R.any
R.contains(3, {1, 2, 3}) --> true
R.contains(4, {1, 2, 3}) --> false
R.contains({ name = 'Fred' }, {{ name = 'Fred' }}) --> true
R.contains({42}, {{42}}) --> true
R.difference Array
Added in v0.1.0
[*] -> [*] -> [*]
see R.differenceWith,R.symmetricDifference,R.symmetricDifferenceWith,R.without
R.difference({1,2,3,4}, {7,6,5,4,3}) --> {1,2}
R.difference({7,6,5,4,3}, {1,2,3,4}) --> {7,6,5}
R.difference({{a = 1}, {b = 2}}, {{a = 1}, {c = 3}}) --> {{b = 2}}
R.differenceWith Array
Added in v0.1.0
((a, a) -> Boolean) -> [a] -> [a] -> [a]
see R.difference,R.symmetricDifference,R.symmetricDifferenceWith
local cmp = function(x, y) return x.a == y.a end
local l1 = {{a = 1}, {a = 2}, {a = 3}}
local l2 = {{a = 3}, {a = 4}}
R.differenceWith(cmp, l1, l2) --> {{a = 1}, {a = 2}}
R.dissoc Array
Added in v0.1.0
String -> {k: v} -> {k: v}
see R.assoc
R.dissoc('b', {a = 1, b = 2, c = 3}) --> {a = 1, c = 3}
R.dissocPath Array
Added in v0.1.0
[Idx] -> {k: v} -> {k: v}
see R.assocPath
R.dissocPath({'a', 'b', 'c'}, {a = {b = {c = 42}}}) --> {a = {b = {}}}
R.drop Array
Added in v0.1.0
Number -> String -> String
see R.take,R.transduce,R.dropLast,R.dropWhile
R.drop(1, {'foo', 'bar', 'baz'}) --> {'bar', 'baz'}
R.drop(2, {'foo', 'bar', 'baz'}) --> {'baz'}
R.drop(3, {'foo', 'bar', 'baz'}) --> {}
R.drop(4, {'foo', 'bar', 'baz'}) --> {}
R.drop(3, 'ramda') --> 'da'
R.dropLast Array
Added in v0.1.0
Number -> String -> String
see R.takeLast,R.drop,R.dropWhile,R.dropLastWhile
R.dropLast(1, {'foo', 'bar', 'baz'}) --> {'foo', 'bar'}
R.dropLast(2, {'foo', 'bar', 'baz'}) --> {'foo'}
R.dropLast(3, {'foo', 'bar', 'baz'}) --> {}
R.dropLast(4, {'foo', 'bar', 'baz'}) --> {}
R.dropLast(3, 'lamda') --> 'la'
R.dropLastWhile Array
Added in v0.1.0
(a -> Boolean) -> [a] -> [a]
see R.takeLastWhile,R.drop,R.dropWhile
R.dropLastWhile(R.gte(3), {1, 2, 3, 4, 3, 2, 1}) --> {1, 2, 3, 4}
R.dropWhile Array
Added in v0.1.0
(a -> Boolean) -> [a] -> [a]
see R.takeWhile
R.dropWhile(R.gte(2), {1, 2, 3, 4, 3, 2, 1}) --> {3, 4, 3, 2, 1}
R.find Array
Added in v0.1.0
(a -> Boolean) -> [a] -> a | nil
local xs = {{a = 1}, {a = 2}, {a = 3}}
R.find(R.propEq('a', 2))(xs) --> {a = 2}
R.find(R.propEq('a', 4))(xs) --> nil
R.findIndex Array
Added in v0.1.0
(a -> Boolean) -> [a] -> Number
local xs = {{a = 1}, {a = 2}, {a = 3}}
R.findIndex(R.propEq('a', 2))(xs) --> 2
R.findIndex(R.propEq('a', 4))(xs) --> -1
R.findLast Array
Added in v0.1.0
(a -> Boolean) -> [a] -> a | nil
local xs = {{a = 1, b = 0}, {a = 1, b = 1}}
R.findLast(R.propEq('a', 1))(xs) --> {a = 1, b = 1}
R.findLast(R.propEq('a', 4))(xs) --> nil
R.findLastIndex Array
Added in v0.1.0
(a -> Boolean) -> [a] -> Number
local xs = {{a = 1, b = 0}, {a = 1, b = 1}}
R.findLastIndex(R.propEq('a', 1))(xs) --> 1
R.findLastIndex(R.propEq('a', 4))(xs) --> -1
R.flatten Array
Added in v0.1.0
[a] -> [b]
see R.unnest
R.flatten({1, 2, {3, 4}, 5, {6, {7, 8, {9, {10, 11}, 12}}}})
--> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
R.groupBy Array
Added in v0.1.0
(a -> String) -> [a] -> {String: [a]}
local byGrade = R.groupBy(function(student)
local score = student.score
return score < 65 and 'F' or
score < 70 and 'D' or
score < 80 and 'C' or
score < 90 and 'B' or 'A'
end)
local students = {{name = 'Lucy', score = 92},
{name = 'Drew', score = 85},
{name = 'Leo', score = 90},
{name = 'Bart', score = 62}}
byGrade(students)
--> {
-- A={{name="Lucy", score=92}, {name="Leo", score=90}},
-- B={{name="Drew", score=85}},
-- F={{name="Bart", score=62}}
-- }
R.groupWith Array
Added in v0.1.0
((a, a) → Boolean) → [a] → [ [a] ]
print(R.toString(R.groupWith(R.equals, {0, 1, 1, 2, 3, 5, 8, 13, 21})))
--> {{0}, {1, 1}, {2}, {3}, {5}, {8}, {13}, {21}}
print(R.toString(R.groupWith(function(a, b) return a + 1 == b end, {0, 1, 1, 2, 3, 5, 8, 13, 21})))
--> {{0, 1}, {1, 2, 3}, {5}, {8}, {13}, {21}}
print(R.toString(R.groupWith(function(a, b) return a % 2 == b % 2 end, {0, 1, 1, 2, 3, 5, 8, 13, 21})))
--> {{0}, {1, 1}, {2}, {3, 5}, {8}, {13, 21}}
print(R.toString(R.groupWith(R.eqBy(R.contains(R.__, "aeiou")), 'aestiou')))
--> {'ae', 'st', 'iou'}
R.head Array
Added in v0.1.0
String -> String
R.head({'fi', 'fo', 'fum'}) --> 'fi'
R.head({}) --> nil
R.head('abc') --> 'a'
R.head('') --> ''
R.includes Array
Added in v0.1.0
Alias To R.contains
R.indexBy Array
Added in v0.1.0
(a -> String) -> [{k: v}] -> {k: {k: v}}
local list = {{id = 'xyz', title = 'A'}, {id = 'abc', title = 'B'}}
R.indexBy(R.prop('id'), list)
--> {abc: {id = 'abc', title = 'B'}, xyz: {id = 'xyz', title = 'A'}}
R.init Array
Added in v0.1.0
String -> String
R.init({1, 2, 3}) --> {1,2}
R.init({1, 2}) --> {1}
R.init({1}) --> {}
R.init({}) --> {}
R.init('abc') --> 'ab'
R.init('ab') --> 'a'
R.init('a') --> ''
R.init('') --> ''
R.innerJoin Array
Added in v0.1.0
(a -> b -> Boolean) -> [a] -> [b] -> [a]
see R.intersection
R.innerJoin(
function(data, id) return data.id == id end,
{{id = 824, name = 'Richie Furay'},
{id = 956, name = 'Dewey Martin'},
{id = 313, name = 'Bruce Palmer'},
{id = 456, name = 'Stephen Stills'},
{id = 177, name = 'Neil Young'}},
{177, 456, 999}
) --> {{name = "Stephen Stills",id = 456},{name = "Neil Young",id = 177}}
R.insert Array
Added in v0.1.0
Number -> a -> [a] -> [a]
R.insert(2, 'x', {1,2,3,4}) --> {1,2,'x',3,4}
R.insertAll Array
Added in v0.1.0
Number -> [a] -> [a] -> [a]
R.insertAll(2, {'x','y','z'}, {1,2,3,4}) --> {1,2,'x','y','z',3,4}
R.intersection Array
Added in v0.1.0
[*] -> [*] -> [*]
see R.innerJoin
R.intersection({1,2,3,4}, {7,6,5,4,3}) --> {3, 4}
R.intersperse Array
Added in v0.1.0
a -> [a] -> [a]
R.intersperse('n', {'ba', 'a', 'a'}) --> {'ba', 'n', 'a', 'n', 'a'}
R.last Array
Added in v0.1.0
String -> String
R.last({'fi', 'fo', 'fum'}) --> 'fum'
R.last({}) --> nil
R.last('abc') --> 'c'
R.last('') --> ''
R.lastIndexOf Array
Added in v0.1.0
a -> [a] -> Number
see R.indexOf
R.lastIndexOf(3, {-1,3,3,0,1,2,3,4}) --> 7
R.lastIndexOf(10, {1,2,3,4}) --> -1
R.length Array
Added in v0.1.0
[a] -> Number
R.length({}) --> 0
R.length({1, 2, 3}) --> 3
R.none Array
Added in v0.1.0
(a -> Boolean) -> [a] -> Boolean
local isEven = n => n % 2 === 0
R.none(isEven, {1, 3, 5, 7, 9, 11}) --> true
R.none(isEven, {1, 3, 5, 7, 8, 11}) --> false
R.nth Array
Added in v0.1.0
Number -> String -> String
local list = {'foo', 'bar', 'baz', 'quux'}
R.nth(1, list) --> 'bar'
R.nth(-1, list) --> 'quux'
R.nth(-99, list) --> nil
R.nth(2, 'abc') --> 'c'
R.nth(3, 'abc') --> ''
R.pair Array
Added in v0.1.0
a -> b -> (a,b)
R.pair('foo', 'bar') --> {'foo', 'bar'}
R.partition Array
Added in v0.1.0
Filterable f => (a -> Boolean) -> f a -> [f a, f a]
R.partition(R.contains('s'), {'sss', 'ttt', 'foo', 'bars'}) --> {{'sss', 'bars'}, {'ttt', 'foo' }}
R.partition(R.contains('s'), {a = 'sss', b = 'ttt', foo = 'bars'}) --> {{ a = 'sss', foo = 'bars' }, { b = 'ttt' }}
R.pluck Array
Added in v0.1.0
Functor f => k -> f {k: v} -> f v
see R.props
R.pluck('a')({{a = 1}, {a = 2}}) --> {1, 2}
R.pluck(0)({{1, 2}, {3, 4}}) --> {1, 3}
R.pluck('val', {a = {val = 3}, b = {val = 5}}) --> {a = 3, b = 5}
R.prepend Array
Added in v0.1.0
a -> [a] -> [a]
see R.append
R.prepend('fee', {'fi', 'fo', 'fum'}) --> {'fee', 'fi', 'fo', 'fum'}
R.push Array
Added in v0.1.0
Alias To R.append
R.range Array
Added in v0.1.0
Number -> Number -> [Number]
R.range(1, 5) --> {1, 2, 3, 4}
R.range(50, 53) --> {50, 51, 52}
R.reduce Array
Added in v0.1.0
((a, b) -> a) -> a -> [b] -> a
see R.reduceRight
R.reduce(R.subtract, 0, {1, 2, 3, 4}) --> ((((0 - 1) - 2) - 3) - 4) = -10
-- - -10
-- / \ / \
-- - 4 -6 4
-- / \ / \
-- - 3 ==> -3 3
-- / \ / \
-- - 2 -1 2
-- / \ / \
-- 0 1 0 1
R.reduceBy Array
Added in v0.1.0
((a, b) -> a) -> a -> (b -> String) -> [b] -> {String: a}
local reduceToNamesBy = R.reduceBy(function(acc, student)
return R.append(student.name, acc)
end, {})
local namesByGrade = reduceToNamesBy(function(student)
local score = student.score
return score < 65 and 'F' or
score < 70 and 'D' or
score < 80 and 'C' or
score < 90 and 'B' or 'A'
end)
local students = {{name = 'Lucy', score = 92},
{name = 'Drew', score = 85},
{name = 'Leo', score = 90},
{name = 'Bart', score = 62}}
namesByGrade(students) --> {A={"Lucy", "Leo"}, B={"Drew"}, F={"Bart"}}
R.reduceWhile Array
Added in v0.1.0
((a, b) -> Boolean) -> ((a, b) -> a) -> a -> [b] -> a
see R.reduce
local isOdd = R.o(R.equals(1), R.mod)
local xs = {1, 3, 5, 60, 777, 800}
R.reduceWhile(isOdd, R.add, 0, xs) --> 9
local ys = {2, 4, 6}
R.reduceWhile(isOdd, R.add, 111, ys) --> 111
R.reject Array
Added in v0.1.0
Filterable f => (a -> Boolean) -> f a -> f a
see R.filter
local isOdd = R.o(R.equals(1), R.mod(R.__, 2))
R.reject(isOdd, {1, 2, 3, 4}) --> {2, 4}
R.reject(isOdd, {a = 1, b = 2, c = 3, d = 4}) --> {b = 2, d = 4}
R.remove Array
Added in v0.1.0
Number -> Number -> [a] -> [a]
R.remove(2, 3, {1,2,3,4,5,6,7,8}) --> {1,2,6,7,8}
R.repeat_ Array
Added in v0.1.0
a -> n -> [a]
see R.times
R.repeat_('hi', 5) --> {'hi', 'hi', 'hi', 'hi', 'hi'}
local obj = {}
local repeatedObjs = R.repeat_(obj, 5) --> {{}, {}, {}, {}, {}}
R.same(repeatedObjs[1], repeatedObjs[2]) --> true
R.reverse Array
Added in v0.1.0
String -> String
R.reverse({1, 2, 3}) --> {3, 2, 1}
R.reverse({1, 2}) --> {2, 1}
R.reverse({1}) --> {1}
R.reverse({}) --> {}
R.reverse('abc') --> 'cba'
R.reverse('ab') --> 'ba'
R.reverse('a') --> 'a'
R.reverse('') --> ''
R.scan Array
Added in v0.1.0
(a,b -> a) -> a -> [b] -> [a]
see R.reduce
local numbers = {1, 2, 3, 4}
local factorials = R.scan(R.multiply, 1, numbers) --> {1, 1, 2, 6, 24}
R.size Array
Added in v0.1.0
Alias To R.length
R.slice Array
Added in v0.1.0
Number -> Number -> String -> String
R.slice(2, 3, {'a', 'b', 'c', 'd'}) --> {'b'}
R.slice(1, -2, {'a', 'b', 'c', 'd'}) --> {'a', 'b'}
R.slice(-3, -1, {'a', 'b', 'c', 'd'}) --> {'b', 'c'}
R.slice(1, 3, 'lamda') --> 'la'
R.sort Array
Added in v0.1.0
(a,a -> Number) -> [a] -> [a]
local diff = R.lt
R.sort(diff, {4,2,7,5}) --> {2, 4, 5, 7}
R.sortWith Array
Added in v0.1.0
[a -> a -> Number] -> [a] -> [a]
local alice = {
name = 'alice',
age = 40
}
local bob = {
name = 'bob',
age = 30
}
local clara = {
name = 'clara',
age = 40
}
local people = {clara, bob, alice}
local ageNameSort = R.sortWith({
R.descend(R.prop('age')),
R.ascend(R.prop('name'))
})
ageNameSort(people) --> {alice, clara, bob}
R.splitAt Array
Added in v0.1.0
Number -> String -> [String, String]
R.splitAt(2, {1, 2, 3}) --> {{1}, {2, 3}}
R.splitAt(6, 'hello world') --> {'hello', ' world'}
R.splitAt(-1, 'foobar') --> {'fooba', 'r'}
R.splitEvery Array
Added in v0.1.0
Number -> String -> [String]
R.splitEvery(3, {1, 2, 3, 4, 5, 6, 7}) --> {{1, 2, 3}, {4, 5, 6}, {7}}
R.splitEvery(3, 'foobarbaz') --> {'foo', 'bar', 'baz'}
R.splitWhen Array
Added in v0.1.0
(a -> Boolean) -> [a] -> [ [a], [a] ]
R.splitWhen(R.equals(2), {1, 2, 3, 1, 2, 3}) --> {{1}, {2, 3, 1, 2, 3}}
R.tail Array
Added in v0.1.0
String -> String
Dispatches to the `slice` method of the first argument, if present.
R.tail({1, 2, 3}) --> {2, 3}
R.tail({1, 2}) --> {2}
R.tail({1}) --> {}
R.tail({}) --> {}
R.tail('abc') --> 'bc'
R.tail('ab') --> 'b'
R.tail('a') --> ''
R.tail('') --> ''
R.take Array
Added in v0.1.0
Number -> String -> String
see R.drop
R.take(1, {'foo', 'bar', 'baz'}) --> {'foo'}
R.take(2, {'foo', 'bar', 'baz'}) --> {'foo', 'bar'}
R.take(3, {'foo', 'bar', 'baz'}) --> {'foo', 'bar', 'baz'}
R.take(4, {'foo', 'bar', 'baz'}) --> {'foo', 'bar', 'baz'}
R.take(3, 'ramda') --> 'ram'
local personnel = {
'Dave Brubeck',
'Paul Desmond',
'Eugene Wright',
'Joe Morello',
'Gerry Mulligan',
'Bob Bates',
'Joe Dodge',
'Ron Crotty'
}
local takeFive = R.take(5)
takeFive(personnel) --> {'Dave Brubeck', 'Paul Desmond', 'Eugene Wright', 'Joe Morello', 'Gerry Mulligan'}
R.takeLast Array
Added in v0.1.0
Number -> String -> String
see R.dropLast
R.takeLast(1, {'foo', 'bar', 'baz'}) --> {'baz'}
R.takeLast(2, {'foo', 'bar', 'baz'}) --> {'bar', 'baz'}
R.takeLast(3, {'foo', 'bar', 'baz'}) --> {'foo', 'bar', 'baz'}
R.takeLast(4, {'foo', 'bar', 'baz'}) --> {'foo', 'bar', 'baz'}
R.takeLast(3, 'lamda') --> 'mda'
R.takeLastWhile Array
Added in v0.1.0
(a -> Boolean) -> [a] -> [a]
see R.dropLastWhile
local isNotOne = R.complement(R.equals(1))
R.takeLastWhile(isNotOne, {1, 2, 3, 4}) --> {2, 3, 4}
R.takeWhile Array
Added in v0.1.0
(a -> Boolean) -> [a] -> [a]
see R.dropWhile
local isNotFour = R.complement(R.equals(4))
R.takeWhile(isNotFour, {1, 2, 3, 4, 3, 2, 1}) --> {1, 2, 3}
R.times Array
Added in v0.1.0
(Number -> a) -> Number -> [a]
see R.repeat
R.times(R.identity, 5) --> {1, 2, 3, 4, 5}
R.transpose Array
Added in v0.1.0
[ [a] ] -> [ [a] ]
R.transpose({{1, 'a'}, {2, 'b'}, {3, 'c'}}) --> {{1, 2, 3}, {"a", "b", "c"}}
R.transpose({{1, 2, 3}, {'a', 'b', 'c'}}) --> {{1, "a"}, {2, "b"}, {3, "c"}}
-- If some of the rows are shorter than the following rows, their elements are skipped:
R.transpose({{10, 11}, {20}, {}, {30, 31, 32}}) --> {{10, 20, 30}, {11, 31}, {32}}
R.unfold Array
Added in v0.1.0
(a -> [b]) -> * -> [b]
local f = function(n)
if n > 50 then return false end
return {-n, n + 10}
end
R.unfold(f, 10) --> {-10, -20, -30, -40, -50}
R.union Array
Added in v0.1.0
[*] -> [*] -> [*]
R.union({1, 2, 3}, {2, 3, 4}) --> {1, 2, 3, 4}
R.unionWith Array
Added in v0.1.0
(a -> a -> Boolean) -> [*] -> [*] -> [*]
see R.union
local l1 = {{a = 1}, {a = 2}}
local l2 = {{a = 1}, {a = 4}}
R.unionWith(R.eqBy(R.prop('a')), l1, l2) --> {{a = 1}, {a = 2}, {a = 4}}
R.uniq Array
Added in v0.1.0
[a] -> [a]
R.uniq({1, 1, 2, 1}) --> {1, 2}
R.uniq({1, '1'}) --> {1, '1'}
R.uniq({{42}, {42}}) --> {{42}}
R.uniqBy Array
Added in v0.1.0
(a -> b) -> [a] -> [a]
R.uniqBy(math.abs, {-1, -5, 2, 10, 1, 2}) --> {-1, -5, 2, 10}
R.uniqWith Array
Added in v0.1.0
(a, a -> Boolean) -> [a] -> [a]
local strEq = R.eqBy(String)
R.uniqWith(strEq)([1, '1', 2, 1]) --> [1, 2]
R.uniqWith(strEq)([{}, {}]) --> [{}]
R.uniqWith(strEq)([1, '1', 1]) --> [1]
R.uniqWith(strEq)(['1', 1, 1]) --> ['1']
R.unnest Array
Added in v0.1.0
Chain c => c (c a) -> c a
R.unnest({1, {2}, {{3}}}) --> {1, 2, {3}}
R.unnest({{1, 2}, {3, 4}, {5, 6}}) --> {1, 2, 3, 4, 5, 6}
R.unshift Array
Added in v0.1.0
Alias To R.prepend
R.update Array
Added in v0.1.0
Number -> a -> [a] -> [a]
see R.adjust
R.update(2, 11, {0, 1, 2}) --> {0, 11, 2}
R.update(2)(11)({0, 1, 2}) --> {0, 11, 2}
R.without Array
Added in v0.1.0
[a] -> [a] -> [a]
see R.difference
R.without({1, 2}, {1, 2, 1, 3, 4}) --> {3, 4}
R.xprod Array
Added in v0.1.0
[a] -> [b] -> [ [a,b] ]
R.xprod({1, 2}, {'a', 'b'}) --> {{1, 'a'}, {1, 'b'}, {2, 'a'}, {2, 'b'}}
R.zip Array
Added in v0.1.0
[a] -> [b] -> [ [a,b] ]
R.zip({1, 2, 3}, {'a', 'b', 'c'}) --> {{1, 'a'}, {2, 'b'}, {3, 'c'}}
R.zipObj Array
Added in v0.1.0
[String] -> [*] -> {String: *}
R.zipObj({'a', 'b', 'c'}, {1, 2, 3}) --> {a = 1, b = 2, c = 3}
R.zipWith Array
Added in v0.1.0
(a,b -> c) -> [a] -> [b] -> [c]
local f = function(x, y)
-- ...
end
R.zipWith(f, {1, 2, 3}, {'a', 'b', 'c'})
--> {f(1, 'a'), f(2, 'b'), f(3, 'c')}
R.F Functional
Added in v0.1.0
* -> Boolean
R.F() --> false
R.T Functional
Added in v0.1.0
* -> Boolean
R.T() --> true
R.allPass Functional
Added in v0.1.0
Not Curried
(*... -> Boolean) -> ... -> (*... -> Boolean)
see R.anyPass
local isQueen = R.propEq('rank', 'Q')
local isSpade = R.propEq('suit', '♠︎')
local isQueenOfSpades = R.allPass(isQueen, isSpade)
isQueenOfSpades({rank = 'Q', suit = '♣︎'}) --> false
isQueenOfSpades({rank = 'Q', suit = '♠︎'}) --> true
R.always Functional
Added in v0.1.0
a -> (* -> a)
local t = R.always('Tee')
t() --> 'Tee'
R.and_ Functional
Added in v0.1.0
a -> b -> a | b
see R.both
R.and(true, true) --> true
R.and(true, false) --> false
R.and(false, true) --> false
R.and(false, false) --> false
R.anyPass Functional
Added in v0.1.0
(*... -> Boolean) -> ... -> (*... -> Boolean)
see R.allPass
local isClub = R.propEq('suit', '♣')
local isSpade = R.propEq('suit', 'â™ ')
local isBlackCard = R.anyPass(isClub, isSpade)
isBlackCard({rank = '10', suit ='♣'}) --> true
isBlackCard({rank = 'Q', suit = 'â™ '}) --> true
isBlackCard({rank = 'Q', suit = '♦'}) --> false
R.apply Functional
Added in v0.1.0
(*... -> a) -> [*] -> a
see R.unapply
local nums = {1, 2, 3, -99, 42, 6, 7}
R.apply(math.max, nums) --> 42
R.ascend Functional
Added in v0.1.0
Ord b => (a -> b) -> a -> a -> Number
see R.descend
local byAge = R.ascend(R.prop('age'))
local people = {
{ name = 'Emma', age = 70 },
{ name = 'Peter', age = 78 },
{ name = 'Mikhail', age = 62 },
}
local peopleByYoungestFirst = R.sort(byAge, people) --> {{ name = 'Mikhail', age: 62 },{ name = 'Emma', age: 70 }, { name = 'Peter', age: 78 }}
R.binary Functional
Added in v0.1.0
(* -> c) -> (a, b -> c)
local takesThreeArgs = function(a, b, c)
return {a, b, c}
end
takesThreeArgs(1, 2, 3) --> {1, 2, 3}
local takesTwoArgs = R.binary(takesThreeArgs)
-- Only 2 arguments are passed to the wrapped function
takesTwoArgs(1, 2, 3) --> {1, 2}
R.bind Functional
Added in v0.1.0
(* -> *) -> {*} -> (* -> *)
see R.partial
local str = "test hello world" --> length 16
local strlen = R.bind(string.len, str)
R.map(strlen, R.split(",", "123,4,56789")) --> {16, 16, 16}
R.both Functional
Added in v0.1.0
(*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
It returns the result of the first function if it is false-y and the result of the second function otherwise. Note that this is short-circuited, meaning that the second function will not be invoked if the first returns a false-y value.
see R.and
local gt10 = R.gt(R.__, 10)
local lt20 = R.lt(R.__, 20)
local f = R.both(gt10, lt20)
f(15) --> true
f(30) --> false
R.call Functional
Added in v0.1.0
(*... -> a),*... -> a
see R.apply
R.call(R.add, 1, 2) --> 3
R.comparator Functional
Added in v0.1.0
(a, b -> Boolean) -> (a, b -> Number)
local byAge = R.comparator(function(a, b) return a.age < b.age end)
local people = {
-- ...
}
local peopleByIncreasingAge = R.sort(byAge, people)
R.complement Functional
Added in v0.1.0
(*... -> *) -> (*... -> Boolean)
see R.not
local isNotNil = R.complement(R.isNil)
R.isNil(nil) --> true
isNotNil(nil) --> false
R.isNil(7) --> false
isNotNil(7) --> true
R.compose Functional
Added in v0.1.0
Not Curried
((y -> z), (x -> y), ..., (o -> p), ((a, b, ..., n) -> o)) -> ((a, b, ..., n) -> z)
see R.pipe
local classyGreeting = function(firstName, lastName)
return "The name's " + lastName + ", " + firstName + " " + lastName
end
local yellGreeting = R.compose(R.toUpper, classyGreeting)
yellGreeting('James', 'Bond') --> "THE NAME'S BOND, JAMES BOND"
R.compose(math.abs, R.add(1), R.multiply(2))(-4) --> 7
R.cond Functional
Added in v0.1.0
[ [(*... -> Boolean),(*... -> *)] ] -> (*... -> *)
local fn = R.cond({
{R.equals(0), R.always('water freezes at 0°C')},
{R.equals(100), R.always('water boils at 100°C')},
{R.T, function(temp) return 'nothing special happens at ' .. temp .. '°C' end}
})
fn(0) --> 'water freezes at 0°C'
fn(50) --> 'nothing special happens at 50°C'
fn(100) --> 'water boils at 100°C'
R.converge Functional
Added in v0.1.0
(x1 -> x2 -> ... -> z) -> [(a -> b -> ... -> x1), (a -> b -> ... -> x2), ...] -> (a -> b -> ... -> z)
see R.useWith
local average = R.converge(R.divide, {R.sum, R.length})
average({1, 2, 3, 4, 5, 6, 7}) --> 4
local strangeConcat = R.converge(R.concat, {R.toUpper, R.toLower})
strangeConcat("Yodel") --> "YODELyodel"
R.curry1 Functional
Added in v0.1.0
Alias To R.curryN
R.curry2 Functional
Added in v0.1.0
Alias To R.curryN
R.curry3 Functional
Added in v0.1.0
Alias To R.curryN
R.curryN Functional
Added in v0.1.0
Number -> (* -> a) -> (* -> a)
see R.curry
local sumArgs = function(...) return R.sum({...}) end
local curriedAddFourNumbers = R.curryN(4, sumArgs)
local f = curriedAddFourNumbers(1, 2)
local g = f(3)
g(4) --> 10
R.descend Functional
Added in v0.1.0
Ord b => (a -> b) -> a -> a -> Number
see R.ascend
local byAge = R.descend(R.prop('age'))
local people = {
{ name = 'Emma', age = 70 },
{ name = 'Peter', age = 78 },
{ name = 'Mikhail', age = 62 },
}
local peopleByYoungestFirst = R.sort(byAge, people) --> {{ name = 'Peter', age: 78 }, { name = 'Emma', age: 70 }, { name = 'Mikhail', age: 62 }}
R.either Functional
Added in v0.1.0
(*... -> Boolean) -> (*... -> Boolean) -> (*... -> Boolean)
see R.or_
local gt10 = function(x) return x > 10 end
local even = function(x) return x % 2 == 0 end
local f = R.either(gt10, even)
f(101) --> true
f(8) --> true
R.flip Functional
Added in v0.1.0
(a -> b -> c -> ... -> z) -> (b -> a -> c -> ... -> z)
local mergeThree = function(a, b, c) return a .. b .. c end
mergeThree('1','2','3') --> "123"
R.flip(mergeThree)('1','2','3') --> "213"
R.identity Functional
Added in v0.1.0
a -> a
R.identity(1) --> 1
local obj = {}
R.identity(obj) == obj --> true
R.ifElse Functional
Added in v0.1.0
(*... -> Boolean) -> (*... -> *) -> (*... -> *) -> (*... -> *)
local incCount = R.ifElse(
R.has('count'),
R.assoc('count', 'null'),
R.assoc('count', 1)
)
print(R.toString(incCount({}))) --> { count: 1 }
print(R.toString(incCount({ count = 1 }))) --> { count = 'null' }
R.juxt Functional
Added in v0.1.0
[(a, b, ..., m) -> n] -> ((a, b, ..., m) -> [n])
see R.applySpec
local getRange = R.juxt({math.min, math.max})
getRange(3, 4, 9, -3) --> {-3, 9}
R.map Functional
Added in v0.1.0
Functor f => (a -> b) -> f a -> f b
local double = x => x * 2
R.map(double, [1, 2, 3]) --> [2, 4, 6]
R.map(double, {x: 1, y: 2, z: 3}) --> [2, 4, 6]
R.mapAccum Functional
Added in v0.1.0
(acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
see R.mapAccumRight
local digits = {'1', '2', '3', '4'}
local appender = R.juxt({R.concat, R.concat})
R.mapAccum(appender, 0, digits) --> {'01234', {'01', '012', '0123', '01234'} }
R.mapAccumRight Functional
Added in v0.1.0
(x-> acc -> (y, acc)) -> acc -> [x] -> ([y], acc)
see R.mapAccum
local digits = {'1', '2', '3', '4'}
local appender = R.juxt({R.concat, R.concat})
R.mapAccumRight(append, 5, digits) --> {{'12345', '2345', '345', '45'}, '12345'}
R.memoize Functional
Added in v0.1.0
(*... -> a) -> (*... -> a)
see R.memoizeWith
local count = 0
local factorial = R.memoize(function(n)
count = count + 1
return R.product(R.range(1, n + 1))
end)
factorial(5) --> 120
factorial(5) --> 120
factorial(5) --> 120
count --> 1
R.memoizeWith Functional
Added in v0.1.0
(*... -> String) -> (*... -> a) -> (*... -> a)
see R.memoize
local count = 0
local factorial = R.memoizeWith(R.identity, function(n)
count = count + 1
return R.product(R.range(1, n + 1))
end)
factorial(5) --> 120
factorial(5) --> 120
factorial(5) --> 120
count --> 1
R.mirror Functional
Added in v0.2.0
a -> [a]
R.mirror(1) --> {1,1}
R.mirror({}) --> {{},{}}
R.mirrorBy Functional
Added in v0.2.0
(a -> * ) -> a -> [a, *]
R.mirrorBy(R.id, 1) --> {1,1}
R.mirrorBy(R.size, {1,2,3}) --> {{1,2,3}, 3}
R.nAry Functional
Added in v0.1.0
Number -> (* -> a) -> (* -> a)
local takesTwoArgs = function (a, b, c, d)
return {a, b, c, d}
end
takesTwoArgs(1, 2, 3, 4) --> {1, 2, 3, 4}
local takesOneArg = R.nAry(3, takesTwoArgs)
-- Only `n` arguments are passed to the wrapped function
takesOneArg(1, 2, 3, 4) --> {1, 2, 3}
R.not_ Functional
Added in v0.1.0
* -> Boolean
see R.complement
R.not(true) --> false
R.not(false) --> true
R.not(0) --> false
R.not(1) --> false
R.o Functional
Added in v0.1.0
(b -> c) -> (a -> b) -> a -> c
local classyGreeting = function(name)
return "The name's " + name.last + ", " + name.first + " " + lastName
end
local yellGreeting = R.o(R.toUpper, classyGreeting)
yellGreeting({first = 'James', last = 'Bond'}) --> "THE NAME'S BOND, JAMES BOND"
R.o(R.multiply(10), R.add(10))(-4) --> 60
R.of Functional
Added in v0.1.0
a -> [a]
R.of(42) --> {42}
R.of({42}) --> {{42}}
R.once Functional
Added in v0.1.0
(a... -> b) -> (a... -> b)
local addOneOnce = R.once(R.add(1))
addOneOnce(10) --> 11
addOneOnce(addOneOnce(50)) --> 11
R.or_ Functional
Added in v0.1.0
a -> b -> a | b
see R.either
R.or(true, true) --> true
R.or(true, false) --> true
R.or(false, true) --> true
R.or(false, false) --> false
R.partial Functional
Added in v0.1.0
((a, b, c, ..., n) -> x) -> a, b, c -> ((d, e, f, ..., n) -> x)
see R.partialRight
local double = R.partial(R.multiply, 2)
double(2) --> 4
local greet = function (salutation, title, firstName, lastName)
return salutation .. ', ' .. title .. ' ' .. firstName .. ' ' .. lastName .. '!'
end
local sayHello = R.partial(greet, 'Hello')
local sayHelloToMs = R.partial(sayHello, 'Ms.')
sayHelloToMs('Jane', 'Jones') --> 'Hello, Ms. Jane Jones!'
R.partialRight Functional
Added in v0.1.0
((a, b, c, ..., n) -> x) -> d, e, f, ..., n -> ((a, b, c, ...) -> x)
see R.partial
local greet = function (salutation, title, firstName, lastName)
return salutation .. ', ' .. title .. ' ' .. firstName .. ' ' .. lastName .. '!'
end
local greetMsJaneJones = R.partialRight(greet, 'Ms.', 'Jane', 'Jones')
greetMsJaneJones('Hello') --> 'Hello, Ms. Jane Jones!'
R.pipe Functional
Added in v0.1.0
Not Curried
(((a, b, ..., n) -> o), (o -> p), ..., (x -> y), (y -> z)) -> ((a, b, ..., n) -> z)
see R.compose
local f = R.pipe(Math.pow, R.negate, R.inc)
f(3, 4) --> -(3^4) + 1
R.tap Functional
Added in v0.1.0
(a -> *) -> a -> a
R.tap(R.partial(R.show, "x is "), 100) --> 100
-->> "x is "100
R.tryCatch Functional
Added in v0.1.0
Not Curried
(...x -> a) [-> ((e, ...x) -> a) -> (...x -> a)] -> (...x -> a)
R.tryCatch(R.prop('x'), R.F)({x = true}) --> true
R.tryCatch(R.prop('x'), R.F)(1) --> false
R.unapply Functional
Added in v0.1.0
([*...] -> a) -> (*... -> a)
see R.apply
R.unapply(R.sum)(1, 2, 3) --> 6
R.unary Functional
Added in v0.1.0
(* -> b) -> (a -> b)
local takesTwoArgs = function(a, b) {
return {a, b}
}
takesTwoArgs(1, 2) --> {1, 2}
local takesOneArg = R.unary(takesTwoArgs)
-- Only 1 argument is passed to the wrapped function
takesOneArg(1, 2) --> {1}
R.unless Functional
Added in v0.1.0
(a -> Boolean) -> (a -> a) -> a -> a
local safeInc = R.unless(R.isString, R.inc)
safeInc('a') -->'a'
safeInc(1) --> 2
end
R.until_ Functional
Added in v0.1.0
(a -> Boolean) -> (a -> a) -> a -> a
R.until_(R.gt(R.__, 100), R.multiply(2))(1) --> 128
R.useWith Functional
Added in v0.1.0
(x1 -> x2 -> ... -> z) -> [(a -> x1), (b -> x2), ...] -> (a -> b -> ... -> z)
see R.converge
R.useWith(math.pow, {R.identity, R.identity})(3, 4) --> 81
R.useWith(math.pow, {R.identity, R.identity})(3)(4) --> 81
R.useWith(math.pow, {R.dec, R.inc})(3, 4) --> 32
R.useWith(math.pow, {R.dec, R.inc})(3)(4) --> 32
R.when Functional
Added in v0.1.0
(a -> Boolean) -> (a -> a) -> a -> a
-- truncate :: String -> String
local truncate = R.when(
R.compose(R.gt(R.__, 10), R.size),
R.pipe(R.take(10), R.append('...'))
)
this.lu.assertEquals(truncate('12345'), '12345') --> '12345'
this.lu.assertEquals(truncate('0123456789ABC'), '0123456789...') --> '0123456789…'
R.abs Math
Added in vv0.2.0
number -> number
R.abs(-5) --> 5
R.add Math
Added in v0.1.0
number -> number -> number
see R.subtract
R.add(2, 3) --> 5
R.add(7)(10) --> 17
R.clamp Math
Added in v0.1.0
Ord a => a -> a -> a -> a
R.clamp(1, 10, -5) --> 1
R.clamp(1, 10, 15) --> 10
R.clamp(1, 10, 4) --> 4
R.dec Math
Added in v0.1.0
Number -> Number
see R.inc
R.dec(42) --> 41
R.divide Math
Added in v0.1.0
Number -> Number -> Number
see R.multiply
R.divide(71, 100) --> 0.71
local half = R.divide(R.__, 2)
half(42) --> 21
local reciprocal = R.divide(1)
reciprocal(4) --> 0.25
R.inc Math
Added in v0.1.0
Number -> Number
see R.dec
R.inc(42) --> 43
R.mean Math
Added in v0.1.0
[Number] -> Number
see R.median
R.mean({2, 7, 9}) --> 6
R.mean({}) --> nan
R.median Math
Added in v0.1.0
[Number] -> Number
see R.mean
R.median({2, 9, 7}) --> 7
R.median({7, 2, 10, 9}) --> 8
R.median({}) --> nan
R.minus Math
Added in v0.1.0
Alias To R.subtract
R.mod Math
Added in v0.1.0
Number -> Number -> Number
R.mod(17, 3) --> 2
local isOdd = R.mod(R.__, 2)
isOdd(42) --> 0
isOdd(21) --> 1
R.multiply Math
Added in v0.1.0
Number -> Number -> Number
see R.divide
local double = R.multiply(2)
local triple = R.multiply(3)
double(3) --> 6
triple(4) --> 12
R.multiply(2, 5) --> 10
R.negate Math
Added in v0.1.0
Number -> Number
R.negate(42) --> -42
R.plus Math
Added in v0.1.0
Alias To R.add
R.product Math
Added in v0.1.0
[Number] -> Number
see R.reduce
R.product({2,4,6,8,100,1}) --> 38400
R.product({}) --> 1
R.subtract Math
Added in v0.1.0
Number -> Number -> Number
see R.add
R.subtract(10, 8) --> 2
local minus5 = R.subtract(R.__, 5)
minus5(17) --> 12
local complementaryAngle = R.subtract(90)
complementaryAngle(30) --> 60
complementaryAngle(72) --> 18
R.sum Math
Added in v0.1.0
[Number] -> Number
see R.reduce
R.sum({2,4,6,8,100,1}) --> 121
R.clone Object
Added in v0.1.0
{*} -> {*}
local objects = {{}, {}, {}}
local objectsClone = R.clone(objects)
objects == objectsClone --> false
objects[1] == objectsClone[1] --> false
R.eqProps Object
Added in v0.1.0
k -> {k: v} -> {k: v} -> Boolean
local o1 = { a = 1, b = 2, c = 3, d = 4 }
local o2 = { a = 10, b = 20, c = 3, d = 40 }
R.eqProps('a', o1, o2) --> false
R.eqProps('c', o1, o2) --> true
R.filter Object
Added in v0.1.0
Filterable f => (a -> Boolean) -> f a -> f a
see R.reject
local isEven = function(n) return n % 2 == 0 end
R.filter(isEven, {1, 2, 3, 4}) --> {2, 4}
R.filter(isEven, {a = 1, b = 2, c = 3, d = 4}) --> {b = 2, d = 4}
R.forEach Object
Added in v0.1.0
(a -> *) -> [a] -> [a]
local printXPlusFive = function(x) print(x + 5) end
R.forEach(printXPlusFive, {1, 2, 3})
--> 6
--> 7
--> 8
R.fromPairs Object
Added in v0.1.0
{{k,v}} -> {k: v}
R.fromPairs({{'a', 1}, {'b', 2}, {'c', 3}}) --> {a = 1, b = 2, c = 3}
R.has Object
Added in v0.1.0
s -> {s: x} -> Boolean
local hasName = R.has('name')
hasName({name = 'alice'}) --> true
hasName({name = 'bob'}) --> true
hasName({}) --> false
local point = {x = 0, y = 0}
local pointHas = R.has(R.__, point)
pointHas('x') --> true
pointHas('y') --> true
pointHas('z') --> false
R.invert Object
Added in v0.1.0
{s: x} -> {x: [ s, ... ]}
see R.invertObj
local raceResultsByFirstName = {
first = 'alice',
second = 'jake',
third = 'alice',
}
R.invert(raceResultsByFirstName) --> { 'alice': {'first', 'third'}, 'jake':{'second'} }
R.invertObj Object
Added in v0.1.0
{s: x} -> {x: s}
see R.invert
local raceResults = {
first = 'alice',
second = 'jake'
}
R.invertObj(raceResults) --> { 'alice' = 'first', 'jake' = 'second' }
-- Alternatively:
local raceResults = {'alice', 'jake'}
R.invertObj(raceResults) --> { alice = 1, jake = 2 }
R.keys Object
Added in v0.1.0
{k: v} -> [k]
see R.values,R.sortedKeys
R.keys({a = 1, b = 2, c = 3}) --> {'a', 'b', 'c'}
R.merge Object
Added in v0.1.0
{k: v} -> {k: v} -> {k: v}
see R.mergeDeepRight,R.mergeWith,R.mergeWithKey
R.merge({ 'name' = 'fred', 'age': 10 }, { 'age': 40 }) --> { 'name' = 'fred', 'age': 40 }
local resetToDefault = R.merge(R.__, {x: 0})
resetToDefault({x: 5, y: 2}) --> {x: 0, y: 2}
R.mergeAll Object
Added in v0.1.0
[{k: v}] -> {k: v}
see R.reduce
R.mergeAll({{foo = 1},{bar = 2},{baz = 3}}) --> {foo:1,bar:2,baz:3}
R.mergeAll({{foo = 1},{foo = 2},{baz = 3}}) --> {foo:2,bar:2}
R.mergeDeepLeft Object
Added in v0.1.0
{a} -> {a} -> {a}
see R.merge,R.mergeDeepRight,R.mergeDeepWith,R.mergeDeepWithKey
R.mergeDeepLeft({ name = 'fred', age = 10, contact = { email = 'moo@example.com' }},
{ age = 40, contact = { email = 'baa@example.com' }})
--> {age=10, contact={email="moo@example.com"}, name="fred"}
R.mergeDeepRight Object
Added in v0.1.0
{a} -> {a} -> {a}
see R.merge,R.mergeDeepLeft,R.mergeDeepWith,R.mergeDeepWithKey
R.mergeDeepRight({ name = 'fred', age = 10, contact = { email = 'moo@example.com' }},
{ age = 40, contact = { email = 'baa@example.com' }})
--> {age=40, contact={email="baa@example.com"}, name="fred"}
R.mergeDeepWith Object
Added in v0.1.0
(a -> a -> a) -> {a} -> {a} -> {a}
see R.mergeWith,R.mergeDeep,R.mergeDeepWithKey
v = R.mergeDeepWith(R.concat,
{ a = true, c = { values = {10, 20} }},
{ b = true, c = { values = {15, 35} }})
--> {a=true, b=true, c={values={10, 20, 15, 35}}}
R.mergeDeepWithKey Object
Added in v0.1.0
(String -> a -> a -> a) -> {a} -> {a} -> {a}
see R.mergeWithKey,R.mergeDeep,R.mergeDeepWith
local concatValues = function(k, l, r)
return k == 'values' and R.concat(l, r) or r
end
R.mergeDeepWithKey(concatValues,
{ a = true, c = { thing = 'foo', values = {10, 20} }},
{ b = true, c = { thing = 'bar', values = {15, 35} }})
--> {a=true, b=true, c={thing="bar", values={10, 20, 15, 35}}}
R.mergeWith Object
Added in v0.1.0
(a -> a -> a) -> {a} -> {a} -> {a}
see R.mergeDeepWith,R.merge,R.mergeWithKey
R.mergeWith(R.concat,
{ a = true, values = {10, 20} },
{ b = true, values = {15, 35} })
--> {a=true, b=true, values = {10, 20, 15, 35}}
R.mergeWithKey Object
Added in v0.1.0
(String -> a -> a -> a) -> {a} -> {a} -> {a}
see R.mergeDeepWithKey,R.merge,R.mergeWith
local concatValues = function(k, l, r)
return k == 'values' and R.concat(l, r) or r
end
v = R.mergeWithKey(concatValues,
{ a = true, thing = 'foo', values = {10, 20} },
{ b = true, thing = 'bar', values = {15, 35} })
--> {a=true, b=true, thing="bar", values={10, 20, 15, 35}}
R.objOf Object
Added in v0.1.0
String -> a -> {String:a}
see R.pair
local matchPhrases = R.compose(
R.objOf('must'),
R.map(R.objOf('match_phrase'))
)
matchPhrases({'foo', 'bar', 'baz'}) --> {must={{match_phrase="foo"}, {match_phrase="bar"}, {match_phrase="baz"}}}
R.omit Object
Added in v0.1.0
[String] -> {String: *} -> {String: *}
see R.pick
R.omit({'a', 'd'}, {a = 1, b = 2, c = 3, d = 4}) --> {b = 2, c = 3}
R.path Object
Added in v0.1.0
[Idx] -> {a} -> a | nil
see R.prop
R.path({'a', 'b'}, {a = {b = 2}}) --> 2
R.path({'a', 'b'}, {c = {b = 2}}) --> nil
R.pathEq Object
Added in v0.1.0
[Idx] -> a -> {a} -> Boolean
local user1 = { address = { zipCode = 90210 } }
local user2 = { address = { zipCode = 55555 } }
local user3 = { name = 'Bob' }
local users = { user1, user2, user3 }
local isFamous = R.pathEq({'address', 'zipCode'}, 90210)
R.filter(isFamous, users) --> {{address={zipCode=90210}}}
R.pathOr Object
Added in v0.1.0
a -> [Idx] -> {a} -> a
R.pathOr('N/A', {'a', 'b'}, {a = {b = 2}}) --> 2
R.pathOr('N/A', {'a', 'b'}, {c = {b = 2}}) --> "N/A"
R.pathSatisfies Object
Added in v0.1.0
(a -> Boolean) -> [Idx] -> {a} -> Boolean
R.pathSatisfies(y => y > 0, {'x', 'y'}, {x = {y = 2}}) --> true
R.pick Object
Added in v0.1.0
[k] -> {k: v} -> {k: v}
R.pick({'a', 'd'}, {a = 1, b = 2, c = 3, d = 4}) --> {a = 1, d = 4}
R.pick({'a', 'e', 'f'}, {a = 1, b = 2, c = 3, d = 4}) --> {a = 1}
R.pickAll Object
Added in vv0.2.0
[k] -> {k: v} -> {k: v}
see R.pick
R.pickAll({'a', 'd'}, {a = 1, b = 2, c = 3, d = 4}) --> {a = 1, d = 4}
R.pickAll({'a', 'e', 'f'}, {a = 1, b = 2, c = 3, d = 4}) --> {a = 1}
R.pickBy Object
Added in v0.1.0
(v, k -> Boolean) -> {k: v} -> {k: v}
local isUpperCase = R.compose(R.safeEquals, R.unpack, R.mirrorBy(R.toUpper), R.second)
R.pickBy(isUpperCase, {a = 1, b = 2, A = 3, B = 4}) --> {A = 3, B = 4}
R.prop Object
Added in v0.1.0
s -> {s: a} -> a | nil
see R.path
R.prop('x', {x = 100}) --> 100
R.prop('x', {}) --> nil
R.prop(1, {'a', 'b'}) --> 'a'
R.prop(-9, {'a', 'b'}) --> nil
R.propEq Object
Added in v0.1.0
String -> a -> Object -> Boolean
local abby = {name = 'Abby', age = 7, hair = 'blond'}
local fred = {name = 'Fred', age = 12, hair = 'brown'}
local rusty = {name = 'Rusty', age = 10, hair = 'brown'}
local alois = {name = 'Alois', age = 15, disposition = 'surly'}
local kids = {abby, fred, rusty, alois}
local hasBrownHair = R.propEq('hair', 'brown')
R.filter(hasBrownHair, kids) --> {fred, rusty}
R.propIs Object
Added in v0.1.0
Type -> String -> Object -> Boolean
see R.is,R.propSatisfies
R.propIs(R.NUMBER, 'x', {x = 1, y = 2}) --> true
R.propIs(R.NUMBER, 'x', {x = 'foo'}) --> false
R.propIs(R.NUMBER, 'x', {}) --> false
R.propOr Object
Added in v0.1.0
a -> String -> Object -> a
local alice = {
name = 'ALICE',
age = 101
}
local favorite = R.prop('favoriteLibrary')
local favoriteWithDefault = R.propOr('Lamda', 'favoriteLibrary')
favorite(alice) --> nil
favoriteWithDefault(alice) --> 'Lamda'
R.propSatisfies Object
Added in v0.1.0
(a -> Boolean) -> String -> {String: a} -> Boolean
R.propSatisfies(R.lt(0), 'x', {x = 1, y = 2}) --> true
R.props Object
Added in v0.1.0
[k] -> {k: v} -> [v]
R.props({'x', 'y'}, {x = 1, y = 2}) --> {1, 2}
R.props({'c', 'a', 'b'}, {b = 2, a = 1}) --> {nil, 1, 2}
local fullName = R.compose(R.join(' '), R.props({'first', 'last'}))
fullName({last = 'Bullet-Tooth', age = 33, first = 'Tony'}) --> 'Tony Bullet-Tooth'
R.skeys Object
Added in v0.1.0
Alias To R.sortedKeys
R.sortedKeys Object
Added in v0.1.0
{k: v} -> [k]
see R.keys
R.sortedKeys({a = 1, x = 2, c = 3}) --> {'a', 'b', 'x'}
R.toPairs Object
Added in v0.1.0
{Key: *} -> [ [Key,*] ]
see R.fromPairs
R.toPairs({a = 1, b = 2, c = 3}) --> {{"a", 1}, {"c", 3}, {"b", 2}}
R.values Object
Added in v0.1.0
{k: v} -> [v]
see R.valuesIn,R.keys
R.values({a: 1, b: 2, c: 3}) --> {1, 2, 3}
R.where Object
Added in v0.1.0
{String: (* -> Boolean)} -> {String: *} -> Boolean
-- pred :: Object -> Boolean
local pred = R.where({
a = R.equals('foo'),
b = R.complement(R.equals('bar')),
x = R.gt(R.__, 10),
y = R.lt(R.__, 20)
})
pred({a = 'foo', b = 'xxx', x = 11, y = 19}) --> true
pred({a = 'xxx', b = 'xxx', x = 11, y = 19}) --> false
pred({a = 'foo', b = 'bar', x = 11, y = 19}) --> false
pred({a = 'foo', b = 'xxx', x = 10, y = 19}) --> false
pred({a = 'foo', b = 'xxx', x = 11, y = 20}) --> false
R.whereEq Object
Added in v0.1.0
{String: *} -> {String: *} -> Boolean
see R.where
-- pred :: Object -> Boolean
local pred = R.whereEq({a = 1, b = 2})
pred({a = 1}) --> false
pred({a = 1, b = 2}) --> true
pred({a = 1, b = 2, c = 3}) --> true
pred({a = 1, b = 1}) --> false
R.boxMullerSampling Random
Added in v0.1.0
Number a => a -> a -> a
R.boxMullerSampling(1, 1)
R.choice Random
Added in v0.1.0
[a] -> a
R.choice({1, 2, 3, 4, 5}) --> 2
R.choice({1, 2, 3, 4, 5}) --> 4
R.normalDistributed Random
Added in v0.1.0
Number a => a -> a -> a -> a
R.normalDistributed(0, 1, 0.7)
R.randrange Random
Added in v0.1.0
Integer a -> a -> a
R.randrange(1, 100) --> 31
R.sample Random
Added in v0.1.0
[a] -> [a]
R.sample(3, {1, 2, 3, 4, 5}) --> 1, 3, 5
R.sample(1, {1, 2, 3, 4, 5}) --> 2
R.shuffle Random
Added in v0.1.0
[a] -> [a]
R.shuffle({1,2,3,4}) --> {4,1,3,2}
R.endsWith String
Added in v0.1.0
String -> Boolean
R.endsWith('c', 'abc') --> true
R.endsWith('b', 'abc') --> false
R.endsWith({'c'}, {'a', 'b', 'c'}) --> true
R.endsWith({'b'}, {'a', 'b', 'c'}) --> false
R.indexOf String
Added in v0.1.0
a -> [a] -> Number
R.indexOf(3, {1,2,3,4}) --> 3
R.indexOf('e', "abcd") --> -1
R.join String
Added in v0.1.0
String -> [a] -> String
see R.split
local spacer = R.join(' ')
spacer({'a', 2, 3.4}) --> 'a 2 3.4'
R.join('|', {1, 2, 3}) --> '1|2|3'
R.match String
Added in v0.1.0
String -> String -> [String | nil]
see R.test
R.match("[a-z]a", 'bananas') --> {"ba", "na", "na"}
R.match("a", 'b') --> {}
R.replace String
Added in v0.1.0
String|String -> String -> String -> String
R.replace('foo', 'bar', 1, 'foo foo foo') --> 'bar foo foo'
R.replace('foo', 'bar', 0, 'foo foo foo') --> 'bar bar bar'
R.split String
Added in v0.1.0
(String | String) -> String -> [String]
see R.join
local pathComponents = R.split('/')
R.tail(pathComponents('/usr/local/bin')) --> {'usr', 'local', 'bin'}
R.split('.', 'a.b.c.xyz.d') --> {'a', 'b', 'c', 'xyz', 'd'}
R.startsWith String
Added in v0.1.0
String -> Boolean
R.startsWith('a', 'abc') --> true
R.startsWith('b', 'abc') --> false
R.startsWith({'a'}, {'a', 'b', 'c'}) --> true
R.startsWith({'b'}, {'a', 'b', 'c'}) --> false
R.strip String
Added in v0.1.0
Alias To R.trim
R.test String
Added in v0.1.0
String -> String -> Boolean
see R.match
R.test("^x", 'xyz') --> true
R.test("^y", 'xyz') --> false
R.toLower String
Added in v0.1.0
String -> String
see R.toUpper
R.toLower('XYZ') --> 'xyz'
R.toUpper String
Added in v0.1.0
String -> String
see R.toLower
R.toUpper('abc') --> 'ABC'
R.trim String
Added in v0.1.0
String -> String
R.trim(' xyz ') --> 'xyz'
R.map(R.trim, R.split(',', 'x, y, z')) --> {'x', 'y', 'z'}
R.count Util
Added in v0.1.0
a -> [a] -> Number
R.count(5, {1,2,5,5,3,2}) --> 2
R.count('a', "hello world") --> 0
R.countBy Util
Added in v0.1.0
(a -> String) -> [a] -> {*}
local numbers = {1.0, 1.1, 1.2, 2.0, 3.0, 2.2}
R.countBy(Math.floor)(numbers) --> {'1': 3, '2': 2, '3': 1}
local letters = {'a', 'b', 'A', 'a', 'B', 'c'}
R.countBy(R.toLower)(letters) --> {'a': 3, 'b': 2, 'c': 1}
R.defaultTo Util
Added in v0.1.0
Not Curried
a -> b -> a | b
R.defaultTo(42, nil) --> 42
R.defaultTo(42, 0/0) --> 42
R.defaultTo(42, 1/0) --> 42
R.defaultTo(42, 100) --> 100
R.empty Util
Added in v0.1.0
a -> a
R.empty(3) --> 0
R.empty(function() end) --> nil
R.empty({1, 2, 3}) --> {}
R.empty('unicorns') --> ''
R.empty({x = 1, y = 2}) --> {}
R.empty(true) --> false
R.eqBy Util
Added in v0.1.0
(a -> b) -> a -> a -> Boolean
R.eqBy(math.abs, 5, -5) --> true
R.equals Util
Added in v0.1.0
a -> b -> Boolean
see R.same
R.equals(1, 1) --> true
R.equals(1, '1') --> false
R.equals({1, 2, 3}, {1, 2, 3}) --> true
local a = {}
a.v = a
local b = {}
b.v = b
R.equals(a, b) --> stack error , don't do this!
R.first Util
Added in v0.1.0
Not Curried
a, *... -> a
local t = R.first('a', 'b', 'c') --> 'a'
local t = R.first() --> nil
R.gt Util
Added in v0.1.0
Ord a => a -> a -> Boolean
see R.lt
R.gt(2, 1) --> true
R.gt(2, 2) --> false
R.gt(2, 3) --> false
R.gt('a', 'z') --> false
R.gt('z', 'a') --> true
R.gte Util
Added in v0.1.0
Ord a => a -> a -> Boolean
see R.lte
R.gte(2, 1) --> true
R.gte(2, 2) --> true
R.gte(2, 3) --> false
R.gte('a', 'z') --> false
R.gte('z', 'a') --> true
R.is Util
Added in v0.1.0
Not Curried
(* -> {*}) -> a -> Boolean
R.is(R.TABLE, {}) --> true
R.is(R.NUMBER, 1) --> true
R.is(R.OBJECT, 1) --> false
R.is(R.STRING, 's') --> true
R.is(R.ARRAY, 's') --> false
R.is(R.NUMBER, {}) --> false
R.isArray Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isBoolean Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isEmpty Util
Added in v0.1.0
Not Curried
a -> Boolean
R.isEmpty({1, 2, 3}) --> false
R.isEmpty({}) --> true
R.isEmpty('') --> true
R.isEmpty(nil) --> true
R.isEmpty({}) --> true
R.isEmpty({length = 0}) --> false
R.isFunction Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isInf Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isInteger Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isNan Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isNil Util
Added in v0.1.0
Not Curried
* -> Boolean
R.isNil(nil) --> true
R.isNil(0) --> false
R.isNil(1/0) --> false
R.isNil(0/0) --> false
R.isNil([]) --> false
R.isNull Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
see R.is
R.isNumber Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isObject Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isSafeArray Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
R.isSafeBoolean Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
see R.is,R.isBoolean
R.isSafeFunction Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
see R.is,R.isFunction
R.isSafeInf Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
R.isSafeInteger Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
see R.is,R.isInteger
R.isSafeNan Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
if val is nil, return false.
R.isSafeNumber Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
see R.is,R.isNumber
R.isSafeObject Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
see R.is,R.isObject
R.isSafeString Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
see R.is,R.isString
R.isSafeTable Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
R.isSafeThread Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
see R.is,R.isThread
R.isSafeUserData Util
Added in v0.2.0
Not Curried
(* -> {*}) -> a -> Boolean
If val is nil, return false.
see R.is,R.isUserData
R.isString Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isTable Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isThread Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.isUserData Util
Added in v0.2.0
(* -> {*}) -> a -> Boolean
see R.is
R.lt Util
Added in v0.1.0
Ord a => a -> a -> Boolean
see R.gt
R.lt(2, 1) --> false
R.lt(2, 2) --> false
R.lt(2, 3) --> true
R.lt('a', 'z') --> true
R.lt('z', 'a') --> false
R.lte Util
Added in v0.1.0
Ord a => a -> a -> Boolean
see R.gte
R.lte(2, 1) --> false
R.lte(2, 2) --> true
R.lte(2, 3) --> true
R.lte('a', 'z') --> true
R.lte('z', 'a') --> false
R.max Util
Added in v0.1.0
Ord a => a -> a -> a
R.max(789, 123) --> 789
R.max('a', 'b') --> 'b'
R.maxBy Util
Added in v0.1.0
Ord b => (a -> b) -> a -> a -> a
local square = function(x) return x*x end
R.maxBy(square, -3, 2) --> -3
R.reduce(R.maxBy(square), 0, {3, -5, 4, 1, -2}) --> -5
R.reduce(R.maxBy(square), 0, {}) --> 0
R.min Util
Added in v0.1.0
Ord a => a -> a -> a
R.min(789, 123) --> 123
R.min('a', 'b') --> 'a'
R.minBy Util
Added in v0.1.0
Ord b => (a -> b) -> a -> a -> a
local square = n => n * n
R.minBy(square, -3, 2) --> 2
R.reduce(R.minBy(square), 100, {3, -5, 4, 1, -2}) --> 1
R.reduce(R.minBy(square), 100, {}) --> 100
R.pack Util
Added in v0.1.0
Not Curried
*... -> [*...]
R.pack(1,2,3,4) --> {1,2,3,4}
R.project Util
Added in v0.1.0
[k] -> [{k: v}] -> [{k: v}]
local abby = {name = 'Abby', age = 7, hair = 'blond', grade = 2}
local fred = {name = 'Fred', age = 12, hair = 'brown', grade = 7}
local kids = {abby, fred}
R.project({'name', 'grade'}, kids) --> {{name = 'Abby', grade = 2}, {name = 'Fred', grade = 7}}
R.safeEquals Util
Added in v0.1.0
Not Curried
Alias To R.equals
R.same Util
Added in v0.1.0
a -> b -> Boolean
see R.equals
R.same(1, 1) --> true
R.same(1, '1') --> false
R.same({1, 2, 3}, {1, 2, 3}) --> false
local a = {}
local b = a
R.same(a, b) --> true
R.second Util
Added in v0.1.0
Not Curried
a, b, *... -> b
local t = R.second('a', 'b', 'c') --> 'b'
local t = R.second('a') --> nil
R.show Util
Added in v0.2.0
Not Curried
* -> nil
R.show(1,2,"hell", {a=b={c="hello"}})
R.symmetricDifference Util
Added in v0.1.0
[*] -> [*] -> [*]
see R.symmetricDifferenceWith,R.difference,R.differenceWith
R.symmetricDifference({1,2,3,4}, {7,6,5,4,3}) --> {1,2,7,6,5}
R.symmetricDifference({7,6,5,4,3}, {1,2,3,4}) --> {7,6,5,1,2}
R.symmetricDifferenceWith Util
Added in v0.1.0
((a, a) -> Boolean) -> [a] -> [a] -> [a]
see R.symmetricDifference,R.difference,R.differenceWith
local eqA = R.eqBy(R.prop('a'))
local l1 = {{a=1}, {a=2}, {a=3}, {a=4}}
local l2 = {{a=3}, {a=4}, {a=5}, {a=6}}
R.symmetricDifferenceWith(eqA, l1, l2) --> {{a=1}, {a=2}, {a=5}, {a=6}}
R.toJson Util
Added in v0.3.0
Not Curried
* -> String
local t = R.toJson() --> "[null]"
local t = R.toJson("") -->
local t = R.toJson({a=1}) --> "{"a":1}"
R.toString Util
Added in v0.1.0
Not Curried
* -> String
local t = R.toString() --> "nil"
local t = R.toString("") --> ""
local t = R.toString({a=1}) --> "{["a"]=1}"