Skip to content

Commit

Permalink
feat: add dropArgs
Browse files Browse the repository at this point in the history
Closes #679
  • Loading branch information
char0n committed Sep 8, 2018
1 parent 40ce295 commit 197b3f1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/dropArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { nAry } from 'ramda';

/**
* Accepts a function with any arity and returns a function with arity of zero.
* The returned function ignores any arguments supplied to it.
*
* @func dropArgs
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/2.10.0|v2.10.0}
* @category Logic
* @sig (...a -> b)-> () -> b
* @param {Function} fn The function with any arity
* @return {Function} Returns function with arity of zero
* @see {@link http://ramdajs.com/docs/#nAry|R.nAry}
* @example
*
* const fn = (a = 1, b = 2) => a + b;
*
* RA.dropArgs(fn)(3, 4); //=> 3
*/
const dropArgs = nAry(0);

export default dropArgs;
6 changes: 6 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,12 @@ declare namespace RamdaAdjunct {
argsPass(combiningPredicate: Function, predicates: Function[]): Function;
argsPass(combiningPredicate: Function): (predicates: Function[]) => Function;

/**
* Accepts a function with any arity and returns a function with arity of zero.
* The returned function ignores any arguments supplied to it.
*/
dropArgs(fn: Function): Function;

/**
* Creates an array with all falsy values removed.
* The values false, null, 0, "", undefined, and NaN are falsy.
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,6 @@ export { default as neither } from './neither';
export { default as notAllPass } from './notAllPass';
export { default as nonePass } from './nonePass';
export { default as argsPass } from './argsPass';
export { default as dropArgs } from './dropArgs';
// Types
export { default as Identity } from './fantasy-land/Identity';
27 changes: 27 additions & 0 deletions test/dropArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as R from 'ramda';

import * as RA from '../src';
import eq from './shared/eq';

describe('dropArgs', function() {
let fn;
let zeroArityFn;

beforeEach(function() {
fn = (a = 1, b = 2) => a + b;
zeroArityFn = RA.dropArgs(fn);
});

it('should drop all arguments', function() {
const actual = zeroArityFn('ignore1', 'ignore2');
const expected = 3;

eq(actual, expected);
});

it('should support placeholder to specify "gaps"', function() {
const dropArgs = RA.dropArgs(R.__);

eq(dropArgs(fn)('ignore1', 'ignore2'), 3);
});
});

0 comments on commit 197b3f1

Please sign in to comment.