nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: sanctuary-js/sanctuary
Pull request #218 (2016-05-18 19:08:35)

array: add S.range
This'll check one more box in #145.


svozza: LGTM.

Patch:
diff --git a/index.js b/index.js
index 842485e..1c8af7a 100644
--- a/index.js
+++ b/index.js
@@ -2670,6 +2670,32 @@
         return result;
       });
 
+  //# range :: Integer -> Integer -> Array Integer
+  //.
+  //. Returns an array of consecutive integers starting with the first argument
+  //. and ending with the second argument minus one. Returns `[]` if the second
+  //. argument is less than or equal to the first argument.
+  //.
+  //. ```javascript
+  //. > S.range(0, 10)
+  //. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+  //.
+  //. > S.range(-5, 0)
+  //. [-5, -4, -3, -2, -1]
+  //.
+  //. > S.range(0, -5)
+  //. []
+  //. ```
+  S.range =
+  def('range',
+      {},
+      [$.Integer, $.Integer, $.Array($.Integer)],
+      function(from, to) {
+        var result = [];
+        for (var n = from; n < to; n += 1) result.push(n);
+        return result;
+      });
+
   //. ### Object
 
   //# prop :: Accessible a => String -> a -> b


Test patch:
diff --git a/test/range.js b/test/range.js
new file mode 100644
index 0000000..3921bd1
--- /dev/null
+++ b/test/range.js
@@ -0,0 +1,56 @@
+'use strict';
+
+var throws = require('assert').throws;
+
+var eq = require('./utils').eq;
+var errorEq = require('./utils').errorEq;
+var S = require('..');
+
+
+describe('range', function() {
+
+  it('is a binary function', function() {
+    eq(typeof S.range, 'function');
+    eq(S.range.length, 2);
+  });
+
+  it('type checks its arguments', function() {
+    throws(function() { S.range(0.5); },
+           errorEq(TypeError,
+                   'Invalid value\n' +
+                   '\n' +
+                   'range :: Integer -> Integer -> Array Integer\n' +
+                   '         ^^^^^^^\n' +
+                   '            1\n' +
+                   '\n' +
+                   '1)  0.5 :: Number, FiniteNumber, NonZeroFiniteNumber, ValidNumber\n' +
+                   '\n' +
+                   'The value at position 1 is not a member of ‘Integer’.\n'));
+
+    throws(function() { S.range(0, 0.5); },
+           errorEq(TypeError,
+                   'Invalid value\n' +
+                   '\n' +
+                   'range :: Integer -> Integer -> Array Integer\n' +
+                   '                    ^^^^^^^\n' +
+                   '                       1\n' +
+                   '\n' +
+                   '1)  0.5 :: Number, FiniteNumber, NonZeroFiniteNumber, ValidNumber\n' +
+                   '\n' +
+                   'The value at position 1 is not a member of ‘Integer’.\n'));
+  });
+
+  it('returns an array of consecutive integers', function() {
+    eq(S.range(0, 0), []);
+    eq(S.range(0, 10), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
+    eq(S.range(0, -10), []);
+    eq(S.range(-2, -1), [-2]);
+    eq(S.range(-2, 3), [-2, -1, 0, 1, 2]);
+  });
+
+  it('is curried', function() {
+    eq(S.range(0).length, 1);
+    eq(S.range(0)(10), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
+  });
+
+});
Repository: sanctuary-js/sanctuary
Pull request #221 (2016-05-25 19:52:39)

combinator: add S.T
In preparation for the upcoming v0.11.0 release I'm updating a rather large project to run against `sanctuary-js/sanctuary#master`. Now that we're embracing curried functions (#182), combinators seem more useful than ever (and `T` seems more useful to me than [`A`][1]).


[1]: http://sanctuary.js.org/#A



Patch:
diff --git a/index.js b/index.js
index cc4ed73..a39c3cd 100644
--- a/index.js
+++ b/index.js
@@ -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]
@@ -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
@@ -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


Test patch:
diff --git a/test/T.js b/test/T.js
new file mode 100644
index 0000000..f140b95
--- /dev/null
+++ b/test/T.js
@@ -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);
+  });
+
+});
Repository: sanctuary-js/sanctuary
Pull request #282 (2016-11-14 01:41:33)

Added function S.on
Closes https://github.com/sanctuary-js/sanctuary/issues/281

davidchambers: Thanks for the pull request, @Bradcomp! There are a few minor things on which I will comment, but overall it looks very good. :)

davidchambers: Thanks for the updates. Providing both `on` and `on_` will be convenient.

One downside of my preference for rebasing is that I don't receive notifications when pull requests are updated. Please leave a comment after making the second round of changes to let me know I should take one last look. :)

Bradcomp: Thanks for your feedback!  I've updated the PR based on your comments.
davidchambers: I'll merge this once you've made the final copy tweak. I appreciate your patience. :)


Patch:
diff --git a/index.js b/index.js
index e89f110..a34f143 100644
--- a/index.js
+++ b/index.js
@@ -750,6 +750,30 @@
   }
   S.pipe = def('pipe', {}, [$.Array($.Function), a, b], pipe);
 
+  //# on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
+  //.
+  //. Takes a binary function `f`, a unary function `g`, and two
+  //. values `x` and `y`. Returns `f(g(x))(g(y))`.
+  //.
+  //. See also [`on_`](#on_).
+  //.
+  //. ```javascript
+  //. > S.on(S.concat, S.reverse, [1, 2, 3], [4, 5, 6])
+  //. [3, 2, 1, 6, 5, 4]
+  //. ```
+  function on(f, g, x, y) {
+    return on_(uncurry2(f), g, x, y);
+  }
+  S.on = def('on', {}, [$.Function, $.Function, a, a, c], on);
+
+  //# on_ :: ((b, b) -> c) -> (a -> b) -> a -> a -> c
+  //.
+  //. Version of [`on`](#on) accepting uncurried functions.
+  function on_(f, g, x, y) {
+    return f(g(x), g(y));
+  }
+  S.on_ = def('on_', {}, [$.Function, $.Function, a, a, c], on_);
+
   //. ### Maybe type
   //.
   //. The Maybe type represents optional values: a value of type `Maybe a` is


Test patch:
diff --git a/test/on.js b/test/on.js
new file mode 100644
index 0000000..6b0ffd9
--- /dev/null
+++ b/test/on.js
@@ -0,0 +1,21 @@
+'use strict';
+
+var S = require('..');
+
+var eq = require('./internal/eq');
+var rem = require('./internal/rem');
+
+
+describe('on', function() {
+
+  it('is a quaternary function', function() {
+    eq(typeof S.on, 'function');
+    eq(S.on.length, 4);
+  });
+
+  it('passes the last two arguments through the modifying function into the converging function', function() {
+    eq(S.on(rem, S.prop('x'), {x: 5, y: 5}, {x: 3, y: 3}), 2);
+    eq(S.on(S.concat, S.reverse)([1, 2, 3], [4, 5, 6]), [3, 2, 1, 6, 5, 4]);
+  });
+
+});
diff --git a/test/on_.js b/test/on_.js
new file mode 100644
index 0000000..4a34138
--- /dev/null
+++ b/test/on_.js
@@ -0,0 +1,20 @@
+'use strict';
+
+var S = require('..');
+
+var eq = require('./internal/eq');
+var rem_ = require('./internal/rem_');
+
+
+describe('on_', function() {
+
+  it('is a quaternary function', function() {
+    eq(typeof S.on_, 'function');
+    eq(S.on_.length, 4);
+  });
+
+  it('passes the last two arguments through the modifying function into the converging function', function() {
+    eq(S.on_(rem_, S.prop('x'), {x: 5, y: 5}, {x: 3, y: 3}), 2);
+  });
+
+});
Repository: sanctuary-js/sanctuary
Pull request #354 (2017-02-24 09:24:37)

Replace Type constructors in env with actual Types
Based on sanctuary-js/sanctuary-def#123

This fixes the inconsistent type of `env`, allowing it to be passed into `$.test`. We should release this as a patch.

Avaq: If `sanctuary-def` exports `Type`, we would also be able to use it in the [definition of `Options`](https://github.com/sanctuary-js/sanctuary/pull/354/files#diff-168726dbe96b3ce427e7fedce31bb0bcR365). For now I don't think we should go for that, as it may be considered "breaking".
davidchambers: Could you update this pull request's destination branch to the temporary `0.12.x` branch I just created?


Patch:
diff --git a/index.js b/index.js
index ed567f9..db96cf1 100644
--- a/index.js
+++ b/index.js
@@ -349,13 +349,13 @@
   var defaultEnv = Z.concat($.env, [
     $.FiniteNumber,
     $.NonZeroFiniteNumber,
-    $Either,
+    $Either($.Unknown, $.Unknown),
     Fn($.Unknown, $.Unknown),
     $.GlobalRegExp,
     $.NonGlobalRegExp,
     $.Integer,
-    $Maybe,
-    $.Pair,
+    $Maybe($.Unknown),
+    $.Pair($.Unknown, $.Unknown),
     $.RegexFlags,
     $.ValidDate,
     $.ValidNumber


Test patch:
diff --git a/test/env.js b/test/env.js
new file mode 100644
index 0000000..a83635f
--- /dev/null
+++ b/test/env.js
@@ -0,0 +1,22 @@
+'use strict';
+
+var $ = require('sanctuary-def');
+
+var S = require('..');
+
+var eq = require('./internal/eq');
+
+
+//  Type :: Type
+var Type = $.NullaryType(
+  'sanctuary/Type',
+  '',
+  function(x) { return S.type(x) === 'sanctuary-def/Type'; }
+);
+
+test('env', function() {
+
+  eq(typeof S.env, 'object');
+  eq($.test([], $.Array(Type), S.env), true);
+
+});
Repository: sanctuary-js/sanctuary
Pull request #389 (2017-05-02 13:52:46)

array: generalize S.find
This leads me to believe that sanctuary-type-classes should ensure consistent enumeration order in [`Object$prototype$reduce`][1] (by sorting the keys). Do others agree that this is desirable?

```haskell
> find (const True) (Map.fromList [("x", 0), ("y", 1)])
Just 0

> find (const True) (Map.fromList [("y", 1), ("x", 0)])
Just 0
```


[1]: https://github.com/sanctuary-js/sanctuary-type-classes/blob/v5.0.0/index.js#L862-L867


gabejohnson: [`Object$prototype$equals`](https://github.com/sanctuary-js/sanctuary-type-classes/blob/1db4db2966bea57e0c6cbab64ca382f2e8a3720c/index.js#L815-L820) and [`Object$prototype$lte`](https://github.com/sanctuary-js/sanctuary-type-classes/blob/1db4db2966bea57e0c6cbab64ca382f2e8a3720c/index.js#L823-L835) already do this. If we're going to be consistent, I don't think we really have a choice.

Patch:
diff --git a/index.js b/index.js
index 3ad21c1..3b667c8 100644
--- a/index.js
+++ b/index.js
@@ -3434,11 +3434,11 @@
   S.joinWith =
   def('joinWith', {}, [$.String, $.Array($.String), $.String], joinWith);
 
-  //# find :: (a -> Boolean) -> Array a -> Maybe a
+  //# find :: Foldable f => (a -> Boolean) -> f a -> Maybe a
   //.
-  //. Takes a predicate and an array and returns Just the leftmost element of
-  //. the array which satisfies the predicate; Nothing if none of the array's
-  //. elements satisfies the predicate.
+  //. Takes a predicate and a structure and returns Just the leftmost element
+  //. of the structure which satisfies the predicate; Nothing if there is no
+  //. such element.
   //.
   //. ```javascript
   //. > S.find(n => n < 0, [1, -2, 3, -4, 5])
@@ -3448,15 +3448,13 @@
   //. Nothing
   //. ```
   function find(pred, xs) {
-    var result = Nothing;
-    xs.some(function(x) {
-      var ok = pred(x);
-      if (ok) result = Just(x);
-      return ok;
-    });
-    return result;
+    return Z.reduce(
+      function(m, x) { return m.isJust ? m : pred(x) ? Just(x) : Nothing; },
+      Nothing,
+      xs
+    );
   }
-  S.find = def('find', {}, [Pred(a), $.Array(a), $Maybe(a)], find);
+  S.find = def('find', {f: [Z.Foldable]}, [Pred(a), f(a), $Maybe(a)], find);
 
   //# pluck :: (Accessible a, Functor f) => String -> f a -> f b
   //.


Test patch:
diff --git a/test/find.js b/test/find.js
index 025b484..706726a 100644
--- a/test/find.js
+++ b/test/find.js
@@ -9,10 +9,14 @@ test('find', function() {
 
   eq(typeof S.find, 'function');
   eq(S.find.length, 2);
-  eq(S.find.toString(), 'find :: (a -> Boolean) -> Array a -> Maybe a');
+  eq(S.find.toString(), 'find :: Foldable f => (a -> Boolean) -> f a -> Maybe a');
 
   eq(S.find(S.even, []), S.Nothing);
   eq(S.find(S.even, [1, 3, 5, 7, 9]), S.Nothing);
   eq(S.find(S.even, [1, 2, 3, 4, 5]), S.Just(2));
+  eq(S.find(S.even, {}), S.Nothing);
+  eq(S.find(S.even, {a: 1, b: 3, c: 5, d: 7, e: 9}), S.Nothing);
+  eq(S.find(S.even, {a: 1, b: 2, c: 3, d: 4, e: 5}), S.Just(2));
+  eq(S.find(S.even, {e: 5, d: 4, c: 3, b: 2, a: 1}), S.Just(2));
 
 });
Repository: sanctuary-js/sanctuary
Pull request #404 (2017-05-30 19:10:06)

array: add S.elem
I just realized we don't have the equivalent of Haskell's [`elem`][1]. We should rectify this. :)

I also just realized that `S.elem(0)` is much nicer than `S.equals(S.Just(0))`!


[1]: http://hackage.haskell.org/package/base-4.9.1.0/docs/Data-Foldable.html#v:elem



Patch:
diff --git a/index.js b/index.js
index 13f3261..367fd86 100644
--- a/index.js
+++ b/index.js
@@ -3461,12 +3461,49 @@
   S.joinWith =
   def('joinWith', {}, [$.String, $.Array($.String), $.String], joinWith);
 
+  //# elem :: (Setoid a, Foldable f) => a -> f a -> Boolean
+  //.
+  //. Takes a value and a structure and returns `true` if the value is an
+  //. element of the structure; `false` otherwise.
+  //.
+  //. See also [`find`](#find).
+  //.
+  //. ```javascript
+  //. > S.elem('c', ['a', 'b', 'c'])
+  //. true
+  //.
+  //. > S.elem('x', ['a', 'b', 'c'])
+  //. false
+  //.
+  //. > S.elem(3, {x: 1, y: 2, z: 3})
+  //. true
+  //.
+  //. > S.elem(8, {x: 1, y: 2, z: 3})
+  //. false
+  //.
+  //. > S.elem(0, S.Just(0))
+  //. true
+  //.
+  //. > S.elem(0, S.Just(1))
+  //. false
+  //.
+  //. > S.elem(0, S.Nothing)
+  //. false
+  //. ```
+  function elem(x, xs) {
+    return Z.reduce(function(b, y) { return b || Z.equals(x, y); }, false, xs);
+  }
+  S.elem =
+  def('elem', {a: [Z.Setoid], f: [Z.Foldable]}, [a, f(a), $.Boolean], elem);
+
   //# find :: Foldable f => (a -> Boolean) -> f a -> Maybe a
   //.
   //. Takes a predicate and a structure and returns Just the leftmost element
   //. of the structure which satisfies the predicate; Nothing if there is no
   //. such element.
   //.
+  //. See also [`elem`](#elem).
+  //.
   //. ```javascript
   //. > S.find(n => n < 0, [1, -2, 3, -4, 5])
   //. Just(-2)


Test patch:
diff --git a/test/elem.js b/test/elem.js
new file mode 100644
index 0000000..32249a5
--- /dev/null
+++ b/test/elem.js
@@ -0,0 +1,22 @@
+'use strict';
+
+var S = require('..');
+
+var eq = require('./internal/eq');
+
+
+test('elem', function() {
+
+  eq(typeof S.elem, 'function');
+  eq(S.elem.length, 2);
+  eq(S.elem.toString(), 'elem :: (Setoid a, Foldable f) => a -> f a -> Boolean');
+
+  eq(S.elem('c', ['a', 'b', 'c']), true);
+  eq(S.elem('x', ['a', 'b', 'c']), false);
+  eq(S.elem(3, {x: 1, y: 2, z: 3}), true);
+  eq(S.elem(8, {x: 1, y: 2, z: 3}), false);
+  eq(S.elem(0, S.Just(0)), true);
+  eq(S.elem(0, S.Just(1)), false);
+  eq(S.elem(0, S.Nothing), false);
+
+});
Repository: sanctuary-js/sanctuary
Pull request #410 (2017-06-07 22:53:12)

parse: parseDate return changed to Maybe ValidDate
Resolves https://github.com/sanctuary-js/sanctuary/issues/406


Patch:
diff --git a/index.js b/index.js
index dda18a0..967f1e0 100644
--- a/index.js
+++ b/index.js
@@ -4084,7 +4084,7 @@
 
   //. ### Parse
 
-  //# parseDate :: String -> Maybe Date
+  //# parseDate :: String -> Maybe ValidDate
   //.
   //. Takes a string and returns Just the date represented by the string
   //. if it does in fact represent a date; Nothing otherwise.
@@ -4100,7 +4100,8 @@
     var date = new Date(s);
     return isNaN(date.valueOf()) ? Nothing : Just(date);
   }
-  S.parseDate = def('parseDate', {}, [$.String, $Maybe($.Date)], parseDate);
+  S.parseDate =
+  def('parseDate', {}, [$.String, $Maybe($.ValidDate)], parseDate);
 
   //  requiredNonCapturingGroup :: Array String -> String
   function requiredNonCapturingGroup(xs) {


Test patch:
diff --git a/test/parseDate.js b/test/parseDate.js
index 96ec8da..ef1a81a 100644
--- a/test/parseDate.js
+++ b/test/parseDate.js
@@ -9,7 +9,7 @@ test('parseDate', function() {
 
   eq(typeof S.parseDate, 'function');
   eq(S.parseDate.length, 1);
-  eq(S.parseDate.toString(), 'parseDate :: String -> Maybe Date');
+  eq(S.parseDate.toString(), 'parseDate :: String -> Maybe ValidDate');
 
   eq(S.parseDate('2001-02-03T04:05:06Z'), S.Just(new Date('2001-02-03T04:05:06Z')));
   eq(S.parseDate('today'), S.Nothing);
Repository: sanctuary-js/sanctuary
Pull request #428 (2017-07-27 12:13:57)

number: add S.pow and S.pow_
These functions sit naturally alongside [`S.sub`][1] and [`S.sub_`][2].


[1]: https://sanctuary.js.org/#sub
[2]: https://sanctuary.js.org/#sub_


svozza: Looks good!

Patch:
diff --git a/index.js b/index.js
index 0226691..60a5885 100644
--- a/index.js
+++ b/index.js
@@ -3842,6 +3842,38 @@
   S.div =
   def('div', {}, [$.FiniteNumber, $.NonZeroFiniteNumber, $.FiniteNumber], div);
 
+  //# pow :: FiniteNumber -> (FiniteNumber -> FiniteNumber)
+  //.
+  //. Takes a finite number `n` and returns the _`n` squared_ function.
+  //.
+  //. See also [`pow_`](#pow_).
+  //.
+  //. ```javascript
+  //. > S.map(S.pow(2), [-3, -2, -1, 0, 1, 2, 3])
+  //. [9, 4, 1, 0, 1, 4, 9]
+  //.
+  //. > S.map(S.pow(0.5), [1, 4, 9, 16, 25])
+  //. [1, 2, 3, 4, 5]
+  //. ```
+  S.pow =
+  def('pow',
+      {},
+      [$.FiniteNumber, Fn($.FiniteNumber, $.FiniteNumber)],
+      flip$(Math.pow));
+
+  //# pow_ :: FiniteNumber -> FiniteNumber -> FiniteNumber
+  //.
+  //. Curried version of [`Math.pow`][].
+  //.
+  //. See also [`pow`](#pow).
+  //.
+  //. ```javascript
+  //. > S.map(S.pow_(10), [-3, -2, -1, 0, 1, 2, 3])
+  //. [0.001, 0.01, 0.1, 1, 10, 100, 1000]
+  //. ```
+  S.pow_ =
+  def('pow_', {}, [$.FiniteNumber, $.FiniteNumber, $.FiniteNumber], Math.pow);
+
   //# mean :: Foldable f => f FiniteNumber -> Maybe FiniteNumber
   //.
   //. Returns the mean of the given array of (finite) numbers.
@@ -4431,6 +4463,7 @@
 //. [Semigroupoid]:     v:fantasyland/fantasy-land#semigroupoid
 //. [Traversable]:      v:fantasyland/fantasy-land#traversable
 //. [UnaryType]:        v:sanctuary-js/sanctuary-def#UnaryType
+//. [`Math.pow`]:       https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow
 //. [`Z.alt`]:          v:sanctuary-js/sanctuary-type-classes#alt
 //. [`Z.ap`]:           v:sanctuary-js/sanctuary-type-classes#ap
 //. [`Z.apFirst`]:      v:sanctuary-js/sanctuary-type-classes#apFirst


Test patch:
diff --git a/test/pow.js b/test/pow.js
new file mode 100644
index 0000000..2945248
--- /dev/null
+++ b/test/pow.js
@@ -0,0 +1,18 @@
+'use strict';
+
+var S = require('..');
+
+var eq = require('./internal/eq');
+
+
+test('pow', function() {
+
+  eq(typeof S.pow, 'function');
+  eq(S.pow.length, 1);
+  eq(S.pow.toString(), 'pow :: FiniteNumber -> (FiniteNumber -> FiniteNumber)');
+
+  eq(S.pow(2)(8), 64);
+  eq(S.map(S.pow(2), [-3, -2, -1, 0, 1, 2, 3]), [9, 4, 1, 0, 1, 4, 9]);
+  eq(S.map(S.pow(0.5), [1, 4, 9, 16, 25]), [1, 2, 3, 4, 5]);
+
+});
diff --git a/test/pow_.js b/test/pow_.js
new file mode 100644
index 0000000..45ba02b
--- /dev/null
+++ b/test/pow_.js
@@ -0,0 +1,18 @@
+'use strict';
+
+var S = require('..');
+
+var eq = require('./internal/eq');
+
+
+test('pow_', function() {
+
+  eq(typeof S.pow_, 'function');
+  eq(S.pow_.length, 2);
+  eq(S.pow_.toString(), 'pow_ :: FiniteNumber -> FiniteNumber -> FiniteNumber');
+
+  eq(S.pow_(8, 2), 64);
+  eq(S.map(S.pow_(10), [0, 1, 2, 3]), [1, 10, 100, 1000]);
+  eq(S.map(S.pow_(10), [-3, -2, -1]), [0.001, 0.01, 0.1]);
+
+});
Repository: sanctuary-js/sanctuary
Pull request #454 (2017-10-31 21:10:24)

Add `S.fromPairs`

davidchambers: Looks very good! I'll leave a few comments, but there's not much to fault here. :)

davidchambers: This looks great to me! Please squash the commits. I'll leave this pull request open for a couple of days to give other Sanctuary contributors an opportunity to comment.

davidchambers: The changes look good, @futpib! I'll merge this pull request as soon as you've made the two minor formatting changes.


Patch:
diff --git a/index.js b/index.js
index 7ac9021..4c313d6 100644
--- a/index.js
+++ b/index.js
@@ -3778,6 +3778,31 @@
   S.pairs =
   def('pairs', {}, [$.StrMap(a), $.Array($.Pair($.String, a))], pairs);
 
+  //# fromPairs :: Foldable f => f (Pair String a) -> StrMap a
+  //.
+  //. Returns a string map containing the key–value pairs specified by the
+  //. given [Foldable][]. If a key appears in multiple pairs, the rightmost
+  //. pair takes precedence.
+  //.
+  //. ```javascript
+  //. > S.fromPairs([['a', 1], ['b', 2], ['c', 3]])
+  //. {a: 1, b: 2, c: 3}
+  //.
+  //. > S.fromPairs([['x', 1], ['x', 2]])
+  //. {x: 2}
+  //. ```
+  function fromPairs(pairs) {
+    return Z.reduce(function(strMap, pair) {
+      strMap[pair[0]] = pair[1];
+      return strMap;
+    }, {}, pairs);
+  }
+  S.fromPairs =
+  def('fromPairs',
+      {f: [Z.Foldable]},
+      [f($.Pair($.String, a)), $.StrMap(a)],
+      fromPairs);
+
   //. ### Number
 
   //# negate :: ValidNumber -> ValidNumber


Test patch:
diff --git a/test/fromPairs.js b/test/fromPairs.js
new file mode 100644
index 0000000..790075a
--- /dev/null
+++ b/test/fromPairs.js
@@ -0,0 +1,19 @@
+'use strict';
+
+var S = require('..');
+
+var eq = require('./internal/eq');
+
+
+test('fromPairs', function() {
+
+  eq(typeof S.fromPairs, 'function');
+  eq(S.fromPairs.length, 1);
+  eq(S.fromPairs.toString(), 'fromPairs :: Foldable f => f (Pair String a) -> StrMap a');
+
+  eq(S.fromPairs([]), {});
+  eq(S.fromPairs([['a', 1], ['b', 2], ['c', 3]]), {a: 1, b: 2, c: 3});
+  eq(S.fromPairs({x: ['a', 1], y: ['b', 2], z: ['c', 3]}), {a: 1, b: 2, c: 3});
+  eq(S.fromPairs([['x', 1], ['x', 2]]), {x: 2});
+
+});