Skip to content

Commit

Permalink
Merge pull request #221 from sanctuary-js/dc-t-combinator
Browse files Browse the repository at this point in the history
combinator: add S.T
  • Loading branch information
davidchambers committed May 26, 2016
2 parents 28236c7 + d60b757 commit aa46d68
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
24 changes: 22 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@
//. function.
//.
//. ```javascript
//. > S.A(S.inc, 1)
//. 2
//. > S.A(S.inc, 42)
//. 43
//.
//. > R.map(S.A(R.__, 100), [S.inc, Math.sqrt])
//. [101, 10]
Expand All @@ -483,6 +483,25 @@
[$.Function, a, b],
function(f, x) { return f(x); });

//# T :: a -> (a -> b) -> b
//.
//. The T ([thrush][]) combinator. Takes a value and a function, and returns
//. the result of applying the function to the value. Equivalent to Haskell's
//. `(&)` function.
//.
//. ```javascript
//. > S.T(42, S.inc)
//. 43
//.
//. > R.map(S.T(100), [S.inc, Math.sqrt])
//. [101, 10]
//. ```
S.T =
def('T',
{},
[a, $.Function, b],
function(x, f) { return f(x); });

//# C :: (a -> b -> c) -> b -> a -> c
//.
//. The C combinator. Takes a curried binary function and two values, and
Expand Down Expand Up @@ -3432,3 +3451,4 @@
//. [UnaryType]: https://github.com/sanctuary-js/sanctuary-def#unarytype
//. [parseInt]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
//. [sanctuary-def]: https://github.com/sanctuary-js/sanctuary-def
//. [thrush]: https://github.com/raganwald-deprecated/homoiconic/blob/master/2008-10-30/thrush.markdown
26 changes: 26 additions & 0 deletions test/T.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var R = require('ramda');

var eq = require('./utils').eq;
var S = require('..');


describe('T', function() {

it('is a binary function', function() {
eq(typeof S.T, 'function');
eq(S.T.length, 2);
});

it('T(x, f) is equivalent to f(x)', function() {
eq(S.T(42, S.inc), 43);
eq(R.map(S.T(100), [S.inc, Math.sqrt]), [101, 10]);
});

it('is curried', function() {
eq(S.T(42).length, 1);
eq(S.T(42)(S.inc), 43);
});

});

0 comments on commit aa46d68

Please sign in to comment.