Repository: sanctuary-js/sanctuary
Pull request #330 (2017-02-04 16:49:47)

Remove extraneous combinators
#### Implications for #216

* [ ] Add a note about `map` being `B` to `S.map` documentation.
* [ ] Remove `S.S` in favor of `S.ap` and add a note to its documentation.
* [ ] Add a note about `join` being `W` to `S.join` documentation.

#### Implications for the future

Maybe we should rename the remaining combinators to their full names.


Patch:
diff --git a/index.js b/index.js
index 05fd66d..2c714a2 100644
--- a/index.js
+++ b/index.js
@@ -571,44 +571,6 @@
   }
   S.T = def('T', {}, [a, Fn(a, b), b], T);
 
-  //# C :: (a -> b -> c) -> b -> a -> c
-  //.
-  //. The C combinator. Takes a curried binary function and two values, and
-  //. returns the result of applying the function to the values in reverse
-  //. order. Equivalent to Haskell's `flip` function.
-  //.
-  //. This function is very similar to [`flip`](#flip), except that its first
-  //. argument must be curried. This allows it to work with manually curried
-  //. functions.
-  //.
-  //. ```javascript
-  //. > S.C(S.concat, 'foo', 'bar')
-  //. 'barfoo'
-  //.
-  //. > Z.map(S.C(S.concat, '?'), ['foo', 'bar', 'baz'])
-  //. ['foo?', 'bar?', 'baz?']
-  //. ```
-  function C(f, x, y) {
-    return f(y)(x);
-  }
-  S.C = def('C', {}, [Fn(a, Fn(b, c)), b, a, c], C);
-
-  //# B :: (b -> c) -> (a -> b) -> a -> c
-  //.
-  //. The B combinator. Takes two functions and a value, and returns the
-  //. result of applying the first function to the result of applying the
-  //. second to the value. Equivalent to [`compose`](#compose) and Haskell's
-  //. `(.)` function.
-  //.
-  //. ```javascript
-  //. > S.B(Math.sqrt, S.inc, 99)
-  //. 10
-  //. ```
-  function B(f, g, x) {
-    return f(g(x));
-  }
-  S.B = def('B', {}, [Fn(b, c), Fn(a, b), a, c], B);
-
   //# S :: (a -> b -> c) -> (a -> b) -> a -> c
   //.
   //. The S combinator. Takes a curried binary function, a unary function,
@@ -727,21 +689,29 @@
       [$.Function([a, b, c, d, e, r]), a, b, c, d, e, r],
       curry5);
 
-  //# flip :: ((a, b) -> c) -> b -> a -> c
+  //# flip :: (a -> b -> c) -> b -> a -> c
   //.
-  //. Takes a binary function and two values, and returns the result of
-  //. applying the function to the values in reverse order.
+  //. Takes a curried binary function and two values, and returns the
+  //. result of applying the function to the values in reverse order.
   //.
-  //. See also [`C`](#C).
+  //. This is the C combinator from combinatory logic.
   //.
   //. ```javascript
-  //. > Z.map(S.flip(Math.pow)(2), [1, 2, 3, 4, 5])
-  //. [1, 4, 9, 16, 25]
+  //. > S.flip(S.concat, 'foo', 'bar')
+  //. 'barfoo'
   //. ```
   function flip(f, x, y) {
+    return f(y)(x);
+  }
+  S.flip = def('flip', {}, [Fn(a, Fn(b, c)), b, a, c], flip);
+
+  //# flip_ :: ((a, b) -> c) -> b -> a -> c
+  //.
+  //. Variant of [`flip`](#flip) which takes an uncurried binary function.
+  function flip_(f, x, y) {
     return f(y, x);
   }
-  S.flip = def('flip', {}, [$.Function([a, b, c]), b, a, c], flip);
+  S.flip_ = def('flip_', {}, [$.Function([a, b, c]), b, a, c], flip_);
 
   //# lift :: Functor f => (a -> b) -> f a -> f b
   //.
@@ -799,20 +769,21 @@
 
   //# compose :: (b -> c) -> (a -> b) -> a -> c
   //.
-  //. Takes two functions assumed to be unary and a value of any type,
-  //. and returns the result of applying the first function to the result
-  //. of applying the second function to the given value.
+  //. Composes two unary functions, from right to left. Equivalent to Haskell's
+  //. `(.)` function.
   //.
-  //. In general terms, `compose` performs right-to-left composition of two
-  //. unary functions.
+  //. This is the B combinator from combinatory logic.
   //.
-  //. See also [`B`](#B) and [`pipe`](#pipe).
+  //. See also [`pipe`](#pipe).
   //.
   //. ```javascript
   //. > S.compose(Math.sqrt, S.inc)(99)
   //. 10
   //. ```
-  S.compose = def('compose', {}, [Fn(b, c), Fn(a, b), a, c], B);
+  function compose(f, g, x) {
+    return f(g(x));
+  }
+  S.compose = def('compose', {}, [Fn(b, c), Fn(a, b), a, c], compose);
 
   //# pipe :: [(a -> b), (b -> c), ..., (m -> n)] -> a -> n
   //.


Test patch:
diff --git a/test/B.js b/test/B.js
deleted file mode 100644
index 5e0754b..0000000
--- a/test/B.js
+++ /dev/null
@@ -1,16 +0,0 @@
-'use strict';
-
-var S = require('..');
-
-var eq = require('./internal/eq');
-
-
-test('B', function() {
-
-  eq(typeof S.B, 'function');
-  eq(S.B.length, 3);
-  eq(S.B.toString(), 'B :: (b -> c) -> (a -> b) -> a -> c');
-
-  eq(S.B(S.mult(2), S.inc, 20), 42);
-
-});
diff --git a/test/C.js b/test/C.js
deleted file mode 100644
index 7964f5c..0000000
--- a/test/C.js
+++ /dev/null
@@ -1,18 +0,0 @@
-'use strict';
-
-var S = require('..');
-
-var eq = require('./internal/eq');
-var map = require('./internal/map');
-
-
-test('C', function() {
-
-  eq(typeof S.C, 'function');
-  eq(S.C.length, 3);
-  eq(S.C.toString(), 'C :: (a -> b -> c) -> b -> a -> c');
-
-  eq(S.C(S.concat, 'foo', 'bar'), 'barfoo');
-  eq(map(S.C(S.concat, '!'))(['BAM', 'POW', 'KA-POW']), ['BAM!', 'POW!', 'KA-POW!']);
-
-});
diff --git a/test/flip.js b/test/flip.js
index fd3d9a3..1bef6b8 100644
--- a/test/flip.js
+++ b/test/flip.js
@@ -10,9 +10,9 @@ test('flip', function() {
 
   eq(typeof S.flip, 'function');
   eq(S.flip.length, 3);
-  eq(S.flip.toString(), 'flip :: ((a, b) -> c) -> b -> a -> c');
+  eq(S.flip.toString(), 'flip :: (a -> b -> c) -> b -> a -> c');
 
-  eq(map(S.flip(Math.pow, 2))([1, 2, 3, 4, 5]), [1, 4, 9, 16, 25]);
-  eq(S.flip(S.indexOf, ['a', 'b', 'c', 'd'], 'c'), S.Just(2));
+  eq(S.flip(S.concat, 'foo', 'bar'), 'barfoo');
+  eq(map(S.flip(S.concat, '!'))(['BAM', 'POW', 'KA-POW']), ['BAM!', 'POW!', 'KA-POW!']);
 
 });
diff --git a/test/flip_.js b/test/flip_.js
new file mode 100644
index 0000000..ba18b89
--- /dev/null
+++ b/test/flip_.js
@@ -0,0 +1,18 @@
+'use strict';
+
+var S = require('..');
+
+var eq = require('./internal/eq');
+var map = require('./internal/map');
+
+
+test('flip_', function() {
+
+  eq(typeof S.flip_, 'function');
+  eq(S.flip_.length, 3);
+  eq(S.flip_.toString(), 'flip_ :: ((a, b) -> c) -> b -> a -> c');
+
+  eq(map(S.flip_(Math.pow, 2))([1, 2, 3, 4, 5]), [1, 4, 9, 16, 25]);
+  eq(S.flip_(S.indexOf, ['a', 'b', 'c', 'd'], 'c'), S.Just(2));
+
+});