Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combinator: add S.T #221

Merged
merged 1 commit into from
May 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});

});