Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ramda/ramda
Browse files Browse the repository at this point in the history
  • Loading branch information
CrossEye committed Nov 28, 2018
2 parents 784d02e + 07e2a56 commit ce73786
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 18 deletions.
2 changes: 1 addition & 1 deletion source/composeWith.js
Expand Up @@ -21,7 +21,7 @@ import reverse from './reverse';
* const composeWhileNotNil = R.composeWith((f, res) => R.isNil(res) ? res : f(res));
*
* composeWhileNotNil([R.inc, R.prop('age')])({age: 1}) //=> 2
* composeWhileNotNil([R.inc, R.prop('age')])({}) //=> null
* composeWhileNotNil([R.inc, R.prop('age')])({}) //=> undefined
*
* @symb R.composeWith(f)([g, h, i])(...args) = f(g, f(h, f(i, ...args)))
*/
Expand Down
1 change: 1 addition & 0 deletions source/index.js
Expand Up @@ -139,6 +139,7 @@ export { default as mergeWithKey } from './mergeWithKey';
export { default as min } from './min';
export { default as minBy } from './minBy';
export { default as modulo } from './modulo';
export { default as move } from './move';
export { default as multiply } from './multiply';
export { default as nAry } from './nAry';
export { default as negate } from './negate';
Expand Down
9 changes: 4 additions & 5 deletions source/memoizeWith.js
Expand Up @@ -4,11 +4,10 @@ import _has from './internal/_has';


/**
* A customisable version of [`R.memoize`](#memoize). `memoizeWith` takes an
* additional function that will be applied to a given argument set and used to
* create the cache key under which the results of the function to be memoized
* will be stored. Care must be taken when implementing key generation to avoid
* clashes that may overwrite previous entries erroneously.
* Takes an additional function that will be applied to a given argument set
* and used to create the cache key under which the results of the function to be
* memoized will be stored. Care must be taken when implementing key generation
* to avoid clashes that may overwrite previous entries erroneously.
*
*
* @func
Expand Down
36 changes: 36 additions & 0 deletions source/move.js
@@ -0,0 +1,36 @@
import _curry3 from './internal/_curry3';

/**
* Move an item, at index `from`, to index `to`, in a list of elements.
* A new list will be created containing the new elements order.
*
* @func
* @memberOf R
* @category List
* @sig Number -> Number -> [a] -> [a]
* @param {Number} from The source index
* @param {Number} to The destination index
* @param {Array} list The list which will serve to realise the move
* @return {Array} The new list reordered
* @example
*
* R.move(0, 2, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['b', 'c', 'a', 'd', 'e', 'f']
* R.move(-1, 0, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['f', 'a', 'b', 'c', 'd', 'e'] list rotation
*/
var move = _curry3(function(from, to, list) {
var length = list.length;
var result = list.slice();
var positiveFrom = from < 0 ? length + from : from;
var positiveTo = to < 0 ? length + to : to;
var item = result.splice(positiveFrom, 1);

return positiveFrom < 0 || positiveFrom >= list.length
|| positiveTo < 0 || positiveTo >= list.length
? list
: []
.concat(result.slice(0, positiveTo))
.concat(item)
.concat(result.slice(positiveTo, list.length));
});

export default move;
2 changes: 1 addition & 1 deletion source/none.js
Expand Up @@ -28,7 +28,7 @@ import all from './all';
* R.none(isEven, [1, 3, 5, 7, 9, 11]); //=> true
* R.none(isOdd, [1, 3, 5, 7, 8, 11]); //=> false
*/
const none = _curry2(function none(fn, input) {
var none = _curry2(function none(fn, input) {
return all(_complement(fn), input);
});
export default none;
7 changes: 4 additions & 3 deletions source/otherwise.js
Expand Up @@ -23,12 +23,13 @@ import _assertPromise from './internal/_assertPromise';
*
* //recoverFromFailure :: String -> Promise ({firstName, lastName})
* var recoverFromFailure = R.pipe(
* failedFetch(12345),
* failedFetch,
* R.otherwise(useDefault),
* R.then(R.pick(['firstName', 'lastName']))
* R.then(R.pick(['firstName', 'lastName'])),
* );
* recoverFromFailure(12345).then(console.log)
*/
const otherwise = _curry2(function otherwise(f, p) {
var otherwise = _curry2(function otherwise(f, p) {
_assertPromise('otherwise', p);

return p.then(null, f);
Expand Down
4 changes: 2 additions & 2 deletions source/pipeWith.js
Expand Up @@ -32,8 +32,8 @@ var pipeWith = _curry2(function pipeWith(xf, list) {
return identity;
}

const headList = head(list);
const tailList = tail(list);
var headList = head(list);
var tailList = tail(list);

return _arity(headList.length, function() {
return _reduce(
Expand Down
2 changes: 1 addition & 1 deletion source/then.js
Expand Up @@ -27,7 +27,7 @@ import _assertPromise from './internal/_assertPromise';
* R.then(R.pick(['firstName', 'lastName']))
* );
*/
const then = _curry2(function then(f, p) {
var then = _curry2(function then(f, p) {
_assertPromise('then', p);

return p.then(f);
Expand Down
2 changes: 1 addition & 1 deletion source/thunkify.js
Expand Up @@ -20,7 +20,7 @@ import _curry1 from './internal/_curry1';
*/
var thunkify = _curry1(function thunkify(fn) {
return curryN(fn.length, function createThunk() {
const fnArgs = arguments;
var fnArgs = arguments;
return function invokeThunk() {
return fn.apply(this, fnArgs);
};
Expand Down
9 changes: 9 additions & 0 deletions test/.eslintrc
@@ -0,0 +1,9 @@
{
"rules": {
"no-restricted-properties": ["error", {
"object": "describe",
"property": "only"
}],
"no-restricted-modules": ["error", ".."]
}
}
2 changes: 1 addition & 1 deletion test/composeWith.js
@@ -1,4 +1,4 @@
var R = require('..');
var R = require('../source');
var eq = require('./shared/eq');


Expand Down
22 changes: 22 additions & 0 deletions test/move.js
@@ -0,0 +1,22 @@
var R = require('../source');
var eq = require('./shared/eq');

var list = ['a', 'b', 'c', 'd', 'e', 'f'];

describe('move', function() {
it('moves an element from an index to another', function() {
eq(R.move(0, 1, list), ['b', 'a', 'c', 'd', 'e', 'f']);
eq(R.move(2, 1, list), ['a', 'c', 'b', 'd', 'e', 'f']);
eq(R.move(-1, 0, list), ['f', 'a', 'b', 'c', 'd', 'e']);
eq(R.move(0, -1, list), ['b', 'c', 'd', 'e', 'f', 'a']);
});

it('does nothing when indexes are outside the list outbounds', function() {
eq(R.move(-20, 2, list), list);
eq(R.move(20, 2, list), list);
eq(R.move(2, 20, list), list);
eq(R.move(2, -20, list), list);
eq(R.move(20, 20, list), list);
eq(R.move(-20, -20, list), list);
});
});
2 changes: 1 addition & 1 deletion test/otherwise.js
@@ -1,6 +1,6 @@
var assert = require('assert');

var R = require('..');
var R = require('../source');
var eq = require('./shared/eq');


Expand Down
2 changes: 1 addition & 1 deletion test/pipeWith.js
@@ -1,4 +1,4 @@
var R = require('..');
var R = require('../source');
var eq = require('./shared/eq');


Expand Down
2 changes: 1 addition & 1 deletion test/then.js
@@ -1,6 +1,6 @@
var assert = require('assert');

var R = require('..');
var R = require('../source');
var eq = require('./shared/eq');


Expand Down

0 comments on commit ce73786

Please sign in to comment.