nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: eslint/eslint
Pull request #10827 (2018-09-02 19:47:16)

Fix: respect generator function expressions in no-constant-condition
<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
-->

**What is the purpose of this pull request? (put an "X" next to item)**

[ ] Documentation update
[X] Bug fix ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/bug-report.md))
[ ] New rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-proposal.md))
[ ] Changes an existing rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-change-proposal.md))
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

<!--
    If the item you've checked above has a template, please paste the template questions below and answer them. (If this pull request is addressing an issue, you can just paste a link to the issue here instead.)
-->
See #10826 for a description of the bug/environment

<!--
    Please ensure your pull request is ready:

    - Read the pull request guide (https://eslint.org/docs/developer-guide/contributing/pull-requests)
    - Include tests for this change
    - Update documentation for this change (if appropriate)
-->

<!--
    The following is required for all pull requests:
-->

**What changes did you make? (Give an overview)**
Made `no-constant-condition` behave the same with respect to generator `FunctionExpression`s as it does for generator `FunctionDeclaration`s

**Is there anything you'd like reviewers to focus on?**





Patch:
diff --git a/lib/rules/no-constant-condition.js b/lib/rules/no-constant-condition.js
index 724da9741..48b1fbf68 100644
--- a/lib/rules/no-constant-condition.js
+++ b/lib/rules/no-constant-condition.js
@@ -207,6 +207,8 @@ module.exports = {
             "ForStatement:exit": checkConstantConditionLoopInSet,
             FunctionDeclaration: enterFunction,
             "FunctionDeclaration:exit": exitFunction,
+            FunctionExpression: enterFunction,
+            "FunctionExpression:exit": exitFunction,
             YieldExpression: () => loopsInCurrentScope.clear()
         };
 


Test patch:
diff --git a/tests/lib/rules/no-constant-condition.js b/tests/lib/rules/no-constant-condition.js
index 1ec03f0e7..69a90dd38 100644
--- a/tests/lib/rules/no-constant-condition.js
+++ b/tests/lib/rules/no-constant-condition.js
@@ -152,6 +152,10 @@ ruleTester.run("no-constant-condition", rule, {
             code: "function foo() {while (true) {function* bar() {while (true) {yield;}}}}",
             errors: [{ messageId: "unexpected", type: "Literal" }]
         },
+        {
+            code: "function foo() {while (true) {const bar = function*() {while (true) {yield;}}}}",
+            errors: [{ messageId: "unexpected", type: "Literal" }]
+        },
         {
             code: "function* foo() { for (let foo = 1 + 2 + 3 + (yield); true; baz) {}}",
             errors: [{ messageId: "unexpected", type: "Literal" }]
Repository: sanctuary-js/sanctuary
Pull request #625 (2019-04-05 18:26:34)

fantasy-land: flip S.alt argument order
The “default” argument should come first, as it's more likely to be known in advance.



Patch:
diff --git a/index.js b/index.js
index 38d7e22..738c006 100644
--- a/index.js
+++ b/index.js
@@ -1204,25 +1204,31 @@
 
   //# alt :: Alt f => f a -> f a -> f a
   //.
-  //. Curried version of [`Z.alt`][].
+  //. Curried version of [`Z.alt`][] with arguments flipped to facilitate
+  //. partial application.
   //.
   //. ```javascript
-  //. > S.alt (S.Nothing) (S.Just (1))
-  //. Just (1)
+  //. > S.alt (S.Just ('default')) (S.Nothing)
+  //. Just ('default')
   //.
-  //. > S.alt (S.Just (2)) (S.Just (3))
-  //. Just (2)
+  //. > S.alt (S.Just ('default')) (S.Just ('hello'))
+  //. Just ('hello')
   //.
-  //. > S.alt (S.Left ('X')) (S.Right (1))
-  //. Right (1)
+  //. > S.alt (S.Right (0)) (S.Left ('X'))
+  //. Right (0)
   //.
-  //. > S.alt (S.Right (2)) (S.Right (3))
-  //. Right (2)
+  //. > S.alt (S.Right (0)) (S.Right (1))
+  //. Right (1)
   //. ```
+  function alt(y) {
+    return function(x) {
+      return Z.alt (x, y);
+    };
+  }
   _.alt = {
     consts: {f: [Z.Alt]},
     types: [f (a), f (a), f (a)],
-    impl: curry2 (Z.alt)
+    impl: alt
   };
 
   //# zero :: Plus f => TypeRep f -> f a


Test patch:
diff --git a/test/alt.js b/test/alt.js
index 9a63a77..40d46c2 100644
--- a/test/alt.js
+++ b/test/alt.js
@@ -12,17 +12,17 @@ test ('alt', () => {
   eq (S.show (S.alt)) ('alt :: Alt f => f a -> f a -> f a');
 
   eq (S.alt ([]) ([])) ([]);
-  eq (S.alt ([]) ([1, 2, 3])) ([1, 2, 3]);
   eq (S.alt ([1, 2, 3]) ([])) ([1, 2, 3]);
-  eq (S.alt ([1, 2, 3]) ([4, 5, 6])) ([1, 2, 3, 4, 5, 6]);
+  eq (S.alt ([]) ([1, 2, 3])) ([1, 2, 3]);
+  eq (S.alt ([4, 5, 6]) ([1, 2, 3])) ([1, 2, 3, 4, 5, 6]);
   eq (S.alt ({}) ({})) ({});
-  eq (S.alt ({}) ({a: 1, b: 2, c: 3})) ({a: 1, b: 2, c: 3});
   eq (S.alt ({a: 1, b: 2, c: 3}) ({})) ({a: 1, b: 2, c: 3});
-  eq (S.alt ({a: 1, b: 2, c: 3}) ({d: 4, e: 5, f: 6})) ({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6});
-  eq (S.alt ({a: 1, b: 2, c: 3}) ({c: 4, d: 5, e: 6})) ({a: 1, b: 2, c: 4, d: 5, e: 6});
+  eq (S.alt ({}) ({a: 1, b: 2, c: 3})) ({a: 1, b: 2, c: 3});
+  eq (S.alt ({d: 4, e: 5, f: 6}) ({a: 1, b: 2, c: 3})) ({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6});
+  eq (S.alt ({c: 4, d: 5, e: 6}) ({a: 1, b: 2, c: 3})) ({a: 1, b: 2, c: 4, d: 5, e: 6});
   eq (S.alt (S.Nothing) (S.Nothing)) (S.Nothing);
-  eq (S.alt (S.Nothing) (S.Just (1))) (S.Just (1));
-  eq (S.alt (S.Just (2)) (S.Nothing)) (S.Just (2));
-  eq (S.alt (S.Just (3)) (S.Just (4))) (S.Just (3));
+  eq (S.alt (S.Just (1)) (S.Nothing)) (S.Just (1));
+  eq (S.alt (S.Nothing) (S.Just (2))) (S.Just (2));
+  eq (S.alt (S.Just (4)) (S.Just (3))) (S.Just (3));
 
 });
Repository: sanctuary-js/sanctuary
Pull request #650 (2019-09-10 21:06:56)

array: update return type of S.size
This is a breaking change if functions' string representations are considered part of the public API, but they are primarily for use in the REPL. Are others comfortable with this change being included in a minor or patch release?



Patch:
diff --git a/index.js b/index.js
index b9030fd..cc4bc54 100644
--- a/index.js
+++ b/index.js
@@ -3024,7 +3024,7 @@
     impl: dropWhile
   };
 
-  //# size :: Foldable f => f a -> Integer
+  //# size :: Foldable f => f a -> NonNegativeInteger
   //.
   //. Returns the number of elements of the given structure.
   //.
@@ -3052,7 +3052,7 @@
   //. ```
   _.size = {
     consts: {f: [Z.Foldable]},
-    types: [f (a), $.Integer],
+    types: [f (a), $.NonNegativeInteger],
     impl: Z.size
   };
 


Test patch:
diff --git a/test/size.js b/test/size.js
index b445259..6420503 100644
--- a/test/size.js
+++ b/test/size.js
@@ -8,7 +8,7 @@ const eq = require ('./internal/eq');
 
 test ('size', () => {
 
-  eq (S.show (S.size)) ('size :: Foldable f => f a -> Integer');
+  eq (S.show (S.size)) ('size :: Foldable f => f a -> NonNegativeInteger');
 
   eq (S.size ([])) (0);
   eq (S.size (['foo'])) (1);
Repository: sanctuary-js/sanctuary
Pull request #682 (2020-07-18 17:49:41)

fantasy-land: add S.reduce_
I've wanted this function many times during the past few years. @sanctuary-js/owners, are you in favour of this addition?



Patch:
diff --git a/index.js b/index.js
index 7257412..2cb4189 100644
--- a/index.js
+++ b/index.js
@@ -1109,10 +1109,15 @@
   //. > S.flip (Cons (Math.floor) (Cons (Math.ceil) (Nil))) (1.5)
   //. Cons (1) (Cons (2) (Nil))
   //. ```
+  function flip(functor) {
+    return function(x) {
+      return Z.flip (functor, x);
+    };
+  }
   _.flip = {
     consts: {f: [Z.Functor]},
     types: [f ($.Fn (a) (b)), a, f (b)],
-    impl: curry2 (Z.flip)
+    impl: flip
   };
 
   //# bimap :: Bifunctor f => (a -> b) -> (c -> d) -> f a c -> f b d
@@ -1229,6 +1234,8 @@
   //. value if the Foldable is empty; the result of the final application
   //. otherwise.
   //.
+  //. See also [`reduce_`](#reduce_).
+  //.
   //. ```javascript
   //. > S.reduce (S.add) (0) ([1, 2, 3, 4, 5])
   //. 15
@@ -1247,10 +1254,28 @@
   }
   _.reduce = {
     consts: {f: [Z.Foldable]},
-    types: [$.Fn (a) ($.Fn (b) (a)), a, f (b), a],
+    types: [$.Fn (b) ($.Fn (a) (b)), b, f (a), b],
     impl: reduce
   };
 
+  //# reduce_ :: Foldable f => (a -> b -> b) -> b -> f a -> b
+  //.
+  //. Variant of [`reduce`](#reduce) that takes a reducing function with
+  //. arguments flipped.
+  //.
+  //. ```javascript
+  //. > S.reduce_ (S.append) ([]) (Cons (1) (Cons (2) (Cons (3) (Nil))))
+  //. [1, 2, 3]
+  //.
+  //. > S.reduce_ (S.prepend) ([]) (Cons (1) (Cons (2) (Cons (3) (Nil))))
+  //. [3, 2, 1]
+  //. ```
+  _.reduce_ = {
+    consts: {f: [Z.Foldable]},
+    types: [$.Fn (a) ($.Fn (b) (b)), b, f (a), b],
+    impl: B (reduce) (flip)
+  };
+
   //# traverse :: (Applicative f, Traversable t) => TypeRep f -> (a -> f b) -> t a -> f (t b)
   //.
   //. Curried version of [`Z.traverse`][].


Test patch:
diff --git a/test/reduce.js b/test/reduce.js
index 2b70f33..f751fcd 100644
--- a/test/reduce.js
+++ b/test/reduce.js
@@ -7,7 +7,7 @@ const eq = require ('./internal/eq');
 
 test ('reduce', () => {
 
-  eq (S.show (S.reduce)) ('reduce :: Foldable f => (a -> b -> a) -> a -> f b -> a');
+  eq (S.show (S.reduce)) ('reduce :: Foldable f => (b -> a -> b) -> b -> f a -> b');
 
   eq (S.reduce (S.concat) ('x') ([])) ('x');
   eq (S.reduce (S.concat) ('x') (['A', 'B', 'C'])) ('xABC');
diff --git a/test/reduce_.js b/test/reduce_.js
new file mode 100644
index 0000000..25d097b
--- /dev/null
+++ b/test/reduce_.js
@@ -0,0 +1,17 @@
+'use strict';
+
+const S = require ('..');
+
+const eq = require ('./internal/eq');
+
+
+test ('reduce_', () => {
+
+  eq (S.show (S.reduce_)) ('reduce_ :: Foldable f => (a -> b -> b) -> b -> f a -> b');
+
+  eq (S.reduce_ (S.append) ([]) ([])) ([]);
+  eq (S.reduce_ (S.append) ([]) ([1, 2, 3])) ([1, 2, 3]);
+  eq (S.reduce_ (S.prepend) ([]) ([])) ([]);
+  eq (S.reduce_ (S.prepend) ([]) ([1, 2, 3])) ([3, 2, 1]);
+
+});
Repository: sanctuary-js/sanctuary
Pull request #690 (2020-08-09 12:46:13)

Change the meaning of `fromEither`
https://github.com/sanctuary-js/sanctuary/pull/644#issuecomment-671040530


Patch:
diff --git a/index.js b/index.js
index 5d3d6fb..a8c244b 100644
--- a/index.js
+++ b/index.js
@@ -2300,28 +2300,24 @@
     impl: fromRight
   };
 
-  //# fromEither :: b -> Either a b -> b
+  //# fromEither :: Either a a -> a
   //.
-  //. Takes a default value and an Either, and returns the Right value
-  //. if the Either is a Right; the default value otherwise.
+  //. Takes an Either with the same type on the Left and on the Right
+  //. and returns whichever value exists.
   //.
-  //. The behaviour of `fromEither` is likely to change in a future release.
-  //. Please use [`fromRight`](#fromRight) instead.
+  //. The inverse of [`tagBy`](#tagBy).
   //.
   //. ```javascript
-  //. > S.fromEither (0) (S.Right (42))
+  //. > S.fromEither (S.Left (42))
   //. 42
   //.
-  //. > S.fromEither (0) (S.Left (42))
-  //. 0
+  //. > S.fromEither (S.Right (42))
+  //. 42
   //. ```
-  function fromEither(x) {
-    return either (K (x)) (I);
-  }
   _.fromEither = {
     consts: {},
-    types: [b, $.Either (a) (b), b],
-    impl: fromEither
+    types: [$.Either (a) (a), a],
+    impl: either (I) (I)
   };
 
   //# lefts :: (Filterable f, Functor f) => f (Either a b) -> f a


Test patch:
diff --git a/test/fromEither.js b/test/fromEither.js
index 615124f..83021ad 100644
--- a/test/fromEither.js
+++ b/test/fromEither.js
@@ -7,9 +7,9 @@ const eq = require ('./internal/eq');
 
 test ('fromEither', () => {
 
-  eq (S.show (S.fromEither)) ('fromEither :: b -> Either a b -> b');
+  eq (S.show (S.fromEither)) ('fromEither :: Either a a -> a');
 
-  eq (S.fromEither (0) (S.Left (42))) (0);
-  eq (S.fromEither (0) (S.Right (42))) (42);
+  eq (S.fromEither (S.Left (42))) (42);
+  eq (S.fromEither (S.Right (42))) (42);
 
 });
Repository: sanctuary-js/sanctuary
Pull request #691 (2020-08-10 06:28:09)

array: rename S.unfoldr
I am not aware of a reason to keep the awkward `r` suffix.

/cc @benperez



Patch:
diff --git a/index.js b/index.js
index 2b76129..8b6cb1b 100644
--- a/index.js
+++ b/index.js
@@ -3367,7 +3367,7 @@
     impl: curry3 (Z.foldMap)
   };
 
-  //# unfoldr :: (b -> Maybe (Pair a b)) -> b -> Array a
+  //# unfold :: (b -> Maybe (Pair a b)) -> b -> Array a
   //.
   //. Takes a function and a seed value, and returns an array generated by
   //. applying the function repeatedly. The array is initially empty. The
@@ -3380,10 +3380,10 @@
   //.     the array and the function is applied to the second element.
   //.
   //. ```javascript
-  //. > S.unfoldr (n => n < 1000 ? S.Just (S.Pair (n) (2 * n)) : S.Nothing) (1)
+  //. > S.unfold (n => n < 1000 ? S.Just (S.Pair (n) (2 * n)) : S.Nothing) (1)
   //. [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
   //. ```
-  function unfoldr(f) {
+  function unfold(f) {
     return function(x) {
       var result = [];
       for (var m = f (x); m.isJust; m = f (m.value.snd)) {
@@ -3392,10 +3392,10 @@
       return result;
     };
   }
-  _.unfoldr = {
+  _.unfold = {
     consts: {},
     types: [$.Fn (b) ($.Maybe ($.Pair (a) (b))), b, $.Array (a)],
-    impl: unfoldr
+    impl: unfold
   };
 
   //# range :: Integer -> Integer -> Array Integer
@@ -4485,7 +4485,7 @@
   function matchAll(pattern) {
     return function(s) {
       return withRegex (pattern, function() {
-        return unfoldr (function(_) {
+        return unfold (function(_) {
           return Z.map (function(ss) {
             return Pair (toMatch (ss)) (null);
           }, Z.reject (equals (null), Just (pattern.exec (s))));


Test patch:
diff --git a/test/unfold.js b/test/unfold.js
new file mode 100644
index 0000000..39e8af2
--- /dev/null
+++ b/test/unfold.js
@@ -0,0 +1,17 @@
+'use strict';
+
+const S = require ('..');
+
+const eq = require ('./internal/eq');
+
+
+test ('unfold', () => {
+
+  eq (S.show (S.unfold)) ('unfold :: (b -> Maybe (Pair a b)) -> b -> Array a');
+
+  const f = n => n >= 5 ? S.Nothing : S.Just (S.Pair (n) (n + 1));
+  eq (S.unfold (f) (5)) ([]);
+  eq (S.unfold (f) (4)) ([4]);
+  eq (S.unfold (f) (1)) ([1, 2, 3, 4]);
+
+});
diff --git a/test/unfoldr.js b/test/unfoldr.js
deleted file mode 100644
index bf5979e..0000000
--- a/test/unfoldr.js
+++ /dev/null
@@ -1,17 +0,0 @@
-'use strict';
-
-const S = require ('..');
-
-const eq = require ('./internal/eq');
-
-
-test ('unfoldr', () => {
-
-  eq (S.show (S.unfoldr)) ('unfoldr :: (b -> Maybe (Pair a b)) -> b -> Array a');
-
-  const f = n => n >= 5 ? S.Nothing : S.Just (S.Pair (n) (n + 1));
-  eq (S.unfoldr (f) (5)) ([]);
-  eq (S.unfoldr (f) (4)) ([4]);
-  eq (S.unfoldr (f) (1)) ([1, 2, 3, 4]);
-
-});
Repository: sanctuary-js/sanctuary
Pull request #699 (2020-08-29 19:23:24)

array: add S.elem_
I find myself flipping [`elem`][1] quite often.

Do you agree with this addition?


[1]: https://sanctuary.js.org/#elem



Patch:
diff --git a/index.js b/index.js
index a216c34..2221e35 100644
--- a/index.js
+++ b/index.js
@@ -3168,7 +3168,7 @@
   //. Takes a value and a structure and returns `true` [iff][] the value is an
   //. element of the structure.
   //.
-  //. See also [`find`](#find).
+  //. See also [`elem_`](#elem_) and [`find`](#find).
   //.
   //. ```javascript
   //. > S.elem ('c') (['a', 'b', 'c'])
@@ -3192,10 +3192,33 @@
   //. > S.elem (0) (S.Nothing)
   //. false
   //. ```
+  var elem = (
+    curry2 (Z.elem)
+  );
   _.elem = {
     consts: {a: [Z.Setoid], f: [Z.Foldable]},
     types: [a, f (a), $.Boolean],
-    impl: curry2 (Z.elem)
+    impl: elem
+  };
+
+  //# elem_ :: (Setoid a, Foldable f) => f a -> a -> Boolean
+  //.
+  //. Variant of [`elem`](#elem) with arguments flipped.
+  //.
+  //. ```javascript
+  //. > S.filter (S.elem_ (['yes', 'oui', 'ja'])) (['yes', 'no'])
+  //. ['yes']
+  //.
+  //. > S.filter (S.elem_ (['yes', 'oui', 'ja'])) (['oui', 'non'])
+  //. ['oui']
+  //.
+  //. > S.filter (S.elem_ (['yes', 'oui', 'ja'])) (['ja', 'nein'])
+  //. ['ja']
+  //. ```
+  _.elem_ = {
+    consts: {a: [Z.Setoid], f: [Z.Foldable]},
+    types: [f (a), a, $.Boolean],
+    impl: C (elem)
   };
 
   //# find :: Foldable f => (a -> Boolean) -> f a -> Maybe a


Test patch:
diff --git a/test/elem_.js b/test/elem_.js
new file mode 100644
index 0000000..5a25fca
--- /dev/null
+++ b/test/elem_.js
@@ -0,0 +1,20 @@
+'use strict';
+
+const S = require ('..');
+
+const eq = require ('./internal/eq');
+
+
+test ('elem_', () => {
+
+  eq (S.show (S.elem_)) ('elem_ :: (Setoid a, Foldable f) => f a -> a -> Boolean');
+
+  eq (S.elem_ (['a', 'b', 'c']) ('c')) (true);
+  eq (S.elem_ (['a', 'b', 'c']) ('x')) (false);
+  eq (S.elem_ ({x: 1, y: 2, z: 3}) (3)) (true);
+  eq (S.elem_ ({x: 1, y: 2, z: 3}) (8)) (false);
+  eq (S.elem_ (S.Just (0)) (0)) (true);
+  eq (S.elem_ (S.Just (1)) (0)) (false);
+  eq (S.elem_ (S.Nothing) (0)) (false);
+
+});