generated from customcommander/project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement
subtract
as an operator function
- Loading branch information
1 parent
cf2b38f
commit 608b408
Showing
7 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @license MIT | ||
* @copyright (c) 2022 Julien Gonzalez <hello@spinjs.com> | ||
*/ | ||
|
||
/** | ||
* @summary | ||
* Functional placeholder. | ||
*/ | ||
module.exports = Symbol(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license MIT | ||
* @copyright (c) 2022 Julien Gonzalez <hello@spinjs.com> | ||
*/ | ||
|
||
const __ = require('./__'); | ||
|
||
/** | ||
* @param {?} a | ||
* @param {?} b | ||
* @return {?} | ||
*/ | ||
module.exports = fn => function (a, b) { | ||
const nargs = arguments.length; | ||
// fn(b) -> a => fn(a, b) | ||
if (nargs == 1) return x => fn(x, a); | ||
// fn(a, __) -> b => fn(a, b) | ||
if (nargs > 1 && b === __) return x => fn(a, x); | ||
return fn(a, b); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @license MIT | ||
* @copyright (c) 2022 Julien Gonzalez <hello@spinjs.com> | ||
*/ | ||
|
||
const op = require('./_operator'); | ||
|
||
/** | ||
* @summary | ||
* Functional equivalent of `a - b`. | ||
* | ||
* @example | ||
* // Remove `2` from all numbers in the list: | ||
* map(subtract(2))([3,4,5]); | ||
* //=> [1,2,3] | ||
* | ||
* @operator | ||
* @function | ||
* @param {number} a | ||
* @param {number} b | ||
* @return {number} | ||
* @see __ | ||
*/ | ||
module.exports = op((a, b) => a - b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const testcheck = require('./_check'); | ||
const {subtract: sut, __} = require('..'); | ||
|
||
testcheck('subtract(a, b)', | ||
['number', 'number'], (a, b) => | ||
sut(a, b) === a - b); | ||
|
||
testcheck('subtract(b)(a)', | ||
['number', 'number'], (a, b) => | ||
sut(b)(a) === a - b); | ||
|
||
testcheck('subtract(a, __)(b)', | ||
['number', 'number'], (a, b) => | ||
sut(a, __)(b) === a - b); |