nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: sanctuary-js/sanctuary
Pull request #473 (2018-01-02 18:51:30)

composition: generalize S.pipe
This change has been discussed in #472.



Patch:
diff --git a/index.js b/index.js
index 24189e3..4c931de 100644
--- a/index.js
+++ b/index.js
@@ -1487,13 +1487,13 @@
       [s(b, c), s(a, b), s(a, c)],
       Z.compose);
 
-  //# pipe :: [(a -> b), (b -> c), ..., (m -> n)] -> a -> n
+  //# pipe :: Foldable f => f (Any -> Any) -> a -> b
   //.
   //. Takes an array of functions assumed to be unary and a value of any type,
   //. and returns the result of applying the sequence of transformations to
   //. the initial value.
   //.
-  //. In general terms, `pipe` performs left-to-right composition of an array
+  //. In general terms, `pipe` performs left-to-right composition of a sequence
   //. of functions. `pipe([f, g, h], x)` is equivalent to `h(g(f(x)))`.
   //.
   //. ```javascript
@@ -1503,7 +1503,7 @@
   function pipe(fs, x) {
     return Z.reduce(function(x, f) { return f(x); }, x, fs);
   }
-  S.pipe = def('pipe', {}, [$.Array($.AnyFunction), a, b], pipe);
+  S.pipe = def('pipe', {f: [Z.Foldable]}, [f(Fn($.Any, $.Any)), a, b], pipe);
 
   //# on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
   //.


Test patch:
diff --git a/test/pipe.js b/test/pipe.js
index 5c51a5a..439dce6 100644
--- a/test/pipe.js
+++ b/test/pipe.js
@@ -1,15 +1,20 @@
 'use strict';
 
-var S = require('..');
+var S = require('./internal/sanctuary');
 
+var List = require('./internal/List');
 var eq = require('./internal/eq');
 
 
+var Cons = List.Cons;
+var Nil = List.Nil;
+
+
 test('pipe', function() {
 
   eq(typeof S.pipe, 'function');
   eq(S.pipe.length, 2);
-  eq(S.pipe.toString(), 'pipe :: Array Function -> a -> b');
+  eq(S.pipe.toString(), 'pipe :: Foldable f => f (Any -> Any) -> a -> b');
 
   eq(S.pipe([], '99'), '99');
   eq(S.pipe([parseInt], '99'), 99);
@@ -17,4 +22,10 @@ test('pipe', function() {
   eq(S.pipe([parseInt, S.add(1), Math.sqrt], '99'), 10);
   eq(S.pipe([parseInt, S.add(1), Math.sqrt, S.sub(1)], '99'), 9);
 
+  eq(S.pipe(Nil, '99'), '99');
+  eq(S.pipe(Cons(parseInt, Nil), '99'), 99);
+  eq(S.pipe(Cons(parseInt, Cons(S.add(1), Nil)), '99'), 100);
+  eq(S.pipe(Cons(parseInt, Cons(S.add(1), Cons(Math.sqrt, Nil))), '99'), 10);
+  eq(S.pipe(Cons(parseInt, Cons(S.add(1), Cons(Math.sqrt, Cons(S.sub(1), Nil)))), '99'), 9);
+
 });
Repository: sanctuary-js/sanctuary
Pull request #609 (2019-03-13 22:22:22)

pair: add S.pair
This function is similar to the functions added in #592 and #593. The fact that `fst`, `snd`, and `swap` can be defined in terms of `pair` demonstrates the foundational nature of `pair`.

__test/pair~.js__ is horribly named for compatibility with case-insensitive file systems. ;)

/cc @puffnfresh



Patch:
diff --git a/index.js b/index.js
index f4f1675..8e370d5 100644
--- a/index.js
+++ b/index.js
@@ -1992,6 +1992,25 @@
     impl: Pair
   };
 
+  //# pair :: (a -> b -> c) -> Pair a b -> c
+  //.
+  //. Case analysis for the `Pair a b` type.
+  //.
+  //. ```javascript
+  //. > S.pair (S.concat) (S.Pair ('foo') ('bar'))
+  //. 'foobar'
+  //. ```
+  function pair(f) {
+    return function(pair) {
+      return f (pair.fst) (pair.snd);
+    };
+  }
+  _.pair = {
+    consts: {},
+    types: [Fn (a) (Fn (b) (c)), $Pair (a) (b), c],
+    impl: pair
+  };
+
   //# fst :: Pair a b -> a
   //.
   //. `fst (Pair (x) (y))` is equivalent to `x`.
@@ -2003,7 +2022,7 @@
   _.fst = {
     consts: {},
     types: [$Pair (a) (b), a],
-    impl: Pair.fst
+    impl: pair (K)
   };
 
   //# snd :: Pair a b -> b
@@ -2017,7 +2036,7 @@
   _.snd = {
     consts: {},
     types: [$Pair (a) (b), b],
-    impl: Pair.snd
+    impl: pair (C (K))
   };
 
   //# swap :: Pair a b -> Pair b a
@@ -2031,7 +2050,7 @@
   _.swap = {
     consts: {},
     types: [$Pair (a) (b), $Pair (b) (a)],
-    impl: Pair.swap
+    impl: pair (C (Pair))
   };
 
   //. ### Maybe type


Test patch:
diff --git a/test/pair~.js b/test/pair~.js
new file mode 100644
index 0000000..366a759
--- /dev/null
+++ b/test/pair~.js
@@ -0,0 +1,16 @@
+'use strict';
+
+const S = require ('..');
+
+const eq = require ('./internal/eq');
+
+
+test ('pair', () => {
+
+  eq (typeof S.pair) ('function');
+  eq (S.pair.length) (1);
+  eq (S.show (S.pair)) ('pair :: (a -> b -> c) -> Pair a b -> c');
+
+  eq (S.pair (S.concat) (S.Pair ('foo') ('bar'))) ('foobar');
+
+});
Repository: websockets/ws
Pull request #1036 (2017-03-08 08:49:17)

Error message for unsupported protcol version
I was playing with making a websocket server and connecting to it using `wscat`, so I did: `wscat -c ws://0.0.0.0 -p 3000` and I got:

> Error: unsupported protocol version

That made me think my webserver was wrong when in fact `-p` is the protocol version and not the port, e.g. `wscat -c ws://0.0.0.0:3000` works.

So I improved the error message:

> Error: unsupported protocol version 3000 (supported versions: 8, 13)

Dorian: Not sure about that coveralls report, seems completely unrelated
lpinca: Technically this is a breaking change as it changes an error message.
lpinca: I don't want to keep this open indefinitely and version 3 is not on sight. I think that very few people (if any) rely on this error message so I'll merge this once comments are addressed and release with the next version.
Dorian: @lpinca Thanks for the review, I updated the code and I think this could help a lot of people setting up / trying websockets and trying to make it work

Patch:
diff --git a/lib/WebSocket.js b/lib/WebSocket.js
index 24bd1bff..f08a96bd 100644
--- a/lib/WebSocket.js
+++ b/lib/WebSocket.js
@@ -21,7 +21,8 @@ const Receiver = require('./Receiver');
 const Sender = require('./Sender');
 
 const closeTimeout = 30 * 1000; // Allow 30 seconds to terminate the connection cleanly.
-const protocolVersion = 13;
+const protocolVersions = [8, 13];
+const protocolVersion = protocolVersions[1];
 
 /**
  * Class representing a WebSocket.
@@ -527,8 +528,11 @@ function initAsClient (address, protocols, options) {
     ca: null
   }, options);
 
-  if (options.protocolVersion !== 8 && options.protocolVersion !== 13) {
-    throw new Error('unsupported protocol version');
+  if (protocolVersions.indexOf(options.protocolVersion) === -1) {
+    throw new Error(
+      `unsupported protocol version: ${options.protocolVersion} ` +
+      `(supported versions: ${protocolVersions.join(', ')})`
+    );
   }
 
   this.protocolVersion = options.protocolVersion;


Test patch:
diff --git a/test/WebSocket.test.js b/test/WebSocket.test.js
index 867629d8..ff01c07b 100644
--- a/test/WebSocket.test.js
+++ b/test/WebSocket.test.js
@@ -51,7 +51,7 @@ describe('WebSocket', function () {
 
       assert.throws(
         () => new WebSocket('ws://localhost', options),
-        /^Error: unsupported protocol version$/
+        /^Error: unsupported protocol version: 1000 \(supported versions: 8, 13\)$/
       );
     });
Repository: websockets/ws
Pull request #1082 (2017-04-20 01:41:42)

#1081: Add headers event to WebSocket.
Adds headers event.

The only thing that's slightly weird about this is that WebSocketServer emits an array of headers, and this emits an object of headers.  We could emit the [rawHeaders](https://nodejs.org/api/http.html#http_message_rawheaders) here, and then they'd match... But most people probably want the headers object anyways.

lpinca: Using `rawHeaders` would be still inconsistent as header field name and header field value are two different elements. In the server sent `headers` event they are a single element.

I think I'm fine with this as is.

Patch:
diff --git a/doc/ws.md b/doc/ws.md
index af3b8556..cdb1f03e 100644
--- a/doc/ws.md
+++ b/doc/ws.md
@@ -226,6 +226,15 @@ human-readable string explaining why the connection has been closed.
 Emitted when an error occurs. Errors from the underlying `net.Socket` are
 forwarded here.
 
+### Event: 'headers'
+
+- `headers` {Object}
+- `response` {http.IncomingMessage}
+
+Emitted when response headers are received from the server as part of the
+handshake.  This allows you to read headers from the server, for example
+'set-cookie' headers.
+
 ### Event: 'message'
 
 - `data` {String|Buffer}
diff --git a/lib/WebSocket.js b/lib/WebSocket.js
index 21a9f105..b835cdfe 100644
--- a/lib/WebSocket.js
+++ b/lib/WebSocket.js
@@ -655,6 +655,8 @@ function initAsClient (address, protocols, options) {
   this._req.on('upgrade', (res, socket, head) => {
     this._req = null;
 
+    this.emit('headers', res.headers, res);
+
     const digest = crypto.createHash('sha1')
       .update(key + constants.GUID, 'binary')
       .digest('base64');


Test patch:
diff --git a/test/WebSocket.test.js b/test/WebSocket.test.js
index 72c4343d..348e112d 100644
--- a/test/WebSocket.test.js
+++ b/test/WebSocket.test.js
@@ -328,6 +328,16 @@ describe('WebSocket', function () {
 
       wss.on('connection', (client) => client.pong());
     });
+
+    it('emits a headers event', function (done) {
+      const wss = new WebSocketServer({ port: ++port }, () => {
+        const ws = new WebSocket(`ws://localhost:${port}`);
+        ws.on('headers', (headers, res) => {
+          assert.strictEqual(headers, res.headers);
+          wss.close(done);
+        });
+      });
+    });
   });
 
   describe('connection establishing', function () {
Repository: websockets/ws
Pull request #1146 (2017-06-19 18:57:50)

Set wasClean to true when close code is between 3000 and 4999
Due to #1144.

3rd-Eden: <3! Thanks for taking the time to contribute <3

Patch:
diff --git a/lib/EventTarget.js b/lib/EventTarget.js
index 8f9a943a..fe173025 100644
--- a/lib/EventTarget.js
+++ b/lib/EventTarget.js
@@ -55,7 +55,7 @@ class CloseEvent extends Event {
   constructor (code, reason, target) {
     super('close', target);
 
-    this.wasClean = code === undefined || code === 1000;
+    this.wasClean = code === undefined || code === 1000 || (code >= 3000 && code <= 4999);
     this.reason = reason;
     this.target = target;
     this.type = 'close';


Test patch:
diff --git a/test/WebSocket.test.js b/test/WebSocket.test.js
index 84fd09ea..0ebfbe52 100644
--- a/test/WebSocket.test.js
+++ b/test/WebSocket.test.js
@@ -1417,6 +1417,32 @@ describe('WebSocket', function () {
       wss.on('connection', (client) => client.close(1000));
     });
 
+    it('should assign "true" to wasClean when server closes with code 3000', function (done) {
+      const wss = new WebSocketServer({ port: ++port }, () => {
+        const ws = new WebSocket(`ws://localhost:${port}`);
+
+        ws.addEventListener('close', (closeEvent) => {
+          assert.ok(closeEvent.wasClean);
+          wss.close(done);
+        });
+      });
+
+      wss.on('connection', (client) => client.close(3000));
+    });
+
+    it('should assign "true" to wasClean when server closes with code 4999', function (done) {
+      const wss = new WebSocketServer({ port: ++port }, () => {
+        const ws = new WebSocket(`ws://localhost:${port}`);
+
+        ws.addEventListener('close', (closeEvent) => {
+          assert.ok(closeEvent.wasClean);
+          wss.close(done);
+        });
+      });
+
+      wss.on('connection', (client) => client.close(4999));
+    });
+
     it('should receive valid CloseEvent when server closes with code 1001', function (done) {
       const wss = new WebSocketServer({ port: ++port }, () => {
         const ws = new WebSocket(`ws://localhost:${port}`);
Repository: DevExpress/devextreme-react
Pull request #97 (2018-05-18 09:59:11)

Fix ID generation for  templates


Patch:
diff --git a/src/core/helpers.ts b/src/core/helpers.ts
index 2c7aeaa..2d8acd2 100644
--- a/src/core/helpers.ts
+++ b/src/core/helpers.ts
@@ -16,6 +16,6 @@ export function addPrefixToKeys(obj: Record<string, any>, prefix: string): Recor
     return result;
 }
 
-export function generateID() {
-    Math.random().toString(36).substr(2);
+export function generateID(): string {
+    return Math.random().toString(36).substr(2);
 }


Test patch:
diff --git a/src/core/component.test.tsx b/src/core/component.test.tsx
index 75d2357..e35f2cd 100644
--- a/src/core/component.test.tsx
+++ b/src/core/component.test.tsx
@@ -259,6 +259,19 @@ describe("templates", () => {
         expect(optionCalls[1][1]).toBe("item");
     });
 
+    it("has templates in state with unique ids", () => {
+        const ItemTemplate = (props: any) => <div className={"template"}>Template {props.text}</div>;
+        const component = mount(
+            <ComponentWithTemplates itemComponent={ItemTemplate} />
+        );
+        renderItemTemplate({text: 1});
+        renderItemTemplate({text: 2});
+
+        const templatesKeys = Object.getOwnPropertyNames(component.state("templates"));
+        expect(templatesKeys.length).toBe(2);
+        expect(templatesKeys[0]).not.toBe(templatesKeys[1]);
+    });
+
     it("removes deleted nodes from state", () => {
         const ItemTemplate = (props: any) => <div className={"template"}>Template {props.text}</div>;
         const component = mount(