nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: plaid/sanctuary
Pull request #5 (2015-02-02 18:10:22)

parse: add S.parseJson
/cc @michaelckelly



Patch:
diff --git a/index.js b/index.js
index 1f7043e..dfa8d63 100644
--- a/index.js
+++ b/index.js
@@ -246,6 +246,15 @@
     return n === n ? Just(n) : Nothing();
   });
 
+  //  parseJson :: String -> Maybe *
+  var parseJson = function(s) {
+    try {
+      return Just(JSON.parse(s));
+    } catch (err) {
+      return Nothing();
+    }
+  };
+
   //  exports  ///////////////////////////////////////////////////////////////
 
   var sanctuary = {
@@ -266,6 +275,7 @@
     or: or,
     parseFloat: parseFloat_,
     parseInt: parseInt_,
+    parseJson: parseJson,
     tail: tail,
     then: then,
     toMaybe: toMaybe,


Test patch:
diff --git a/test/index.js b/test/index.js
index ef79461..a36add3 100644
--- a/test/index.js
+++ b/test/index.js
@@ -559,4 +559,20 @@ describe('parse', function() {
 
   });
 
+  describe('parseJson', function() {
+
+    it('returns a Just when applied to a valid JSON string', function() {
+      var xs = S.fromMaybe(null, S.parseJson('["foo","bar"]'));
+      eq(Object.prototype.toString.call(xs), '[object Array]');
+      eq(xs.length, 2);
+      eq(xs[0], 'foo');
+      eq(xs[1], 'bar');
+    });
+
+    it('returns a Nothing when applied to an invalid JSON string', function() {
+      assert(S.parseJson('[Invalid JSON]').equals(S.Nothing()));
+    });
+
+  });
+
 });
Repository: plaid/sanctuary
Pull request #6 (2015-02-07 00:10:21)

maybe: add S.encase
> __encase__
> _verb_
> enclose or cover in a case or close-fitting surround

As I imagine it we're _encasing_ a function which may explode in an indestructible wrapper. Alternative name suggestions welcome.


buzzdecafe: ...and the puns you can make now... "Just encase"
davidchambers: Very punny, @buzzdecafe.


Patch:
diff --git a/index.js b/index.js
index 64d32db..ceba0cf 100644
--- a/index.js
+++ b/index.js
@@ -121,6 +121,17 @@
     return x == null ? Nothing() : Just(x);
   };
 
+  //  encase :: (* -> a) -> (* -> Maybe a)
+  var encase = function(f) {
+    return function() {
+      try {
+        return Just(f.apply(this, arguments));
+      } catch (err) {
+        return Nothing();
+      }
+    };
+  };
+
   //  either  ////////////////////////////////////////////////////////////////
 
   function Either() {
@@ -239,13 +250,7 @@
   });
 
   //  parseJson :: String -> Maybe *
-  var parseJson = function(s) {
-    try {
-      return Just(JSON.parse(s));
-    } catch (err) {
-      return Nothing();
-    }
-  };
+  var parseJson = encase(JSON.parse);
 
   //  exports  ///////////////////////////////////////////////////////////////
 
@@ -258,6 +263,7 @@
     Right: Right,
     at: at,
     either: either,
+    encase: encase,
     get: get,
     head: head,
     init: init,


Test patch:
diff --git a/test/index.js b/test/index.js
index a7cbc39..5fb6f35 100644
--- a/test/index.js
+++ b/test/index.js
@@ -169,6 +169,40 @@ describe('maybe', function() {
 
   });
 
+  describe('encase', function() {
+
+    //  factorial :: Number -> Number
+    var factorial = function(n) {
+      if (n < 0) {
+        throw new Error('Cannot determine factorial of negative number');
+      } else if (n === 0) {
+        return 1;
+      } else {
+        return n * factorial(n - 1);
+      }
+    };
+
+    it('returns a function which returns a Just on success', function() {
+      assert(S.encase(factorial)(5).equals(S.Just(120)));
+    });
+
+    it('returns a function which returns a Nothing on failure', function() {
+      assert(S.encase(factorial)(-1).equals(S.Nothing()));
+    });
+
+    it('can be applied to a function of arbitrary arity', function() {
+      var f = S.encase(function(a, b, c, d, e) { return e; });
+      assert(f(1, 2, 3, 4, 5).equals(S.Just(5)));
+    });
+
+    it('preserves context', function() {
+      var f = S.encase(function() { return this; });
+      var ctx = {};
+      assert(f.call(ctx).equals(S.Just(ctx)));
+    });
+
+  });
+
 });
 
 describe('either', function() {
Repository: plaid/sanctuary
Pull request #7 (2015-02-07 02:26:53)

parse: add S.parseDate
No good can come of an "Invalid Date" object.



Patch:
diff --git a/index.js b/index.js
index 64d32db..29f86b6 100644
--- a/index.js
+++ b/index.js
@@ -226,6 +226,12 @@
 
   //  parse  /////////////////////////////////////////////////////////////////
 
+  //  parseDate :: String -> Maybe Date
+  var parseDate = function(s) {
+    var d = new Date(s);
+    return d.valueOf() === d.valueOf() ? Just(d) : Nothing();
+  };
+
   //  parseFloat_ :: String -> Maybe Number
   var parseFloat_ = function(s) {
     var n = parseFloat(s);
@@ -264,6 +270,7 @@
     fromMaybe: fromMaybe,
     last: last,
     or: or,
+    parseDate: parseDate,
     parseFloat: parseFloat_,
     parseInt: parseInt_,
     parseJson: parseJson,


Test patch:
diff --git a/test/index.js b/test/index.js
index a7cbc39..68eaa84 100644
--- a/test/index.js
+++ b/test/index.js
@@ -463,6 +463,22 @@ describe('object', function() {
 
 describe('parse', function() {
 
+  describe('parseDate', function() {
+
+    it('returns a Just when applied to a valid date string', function() {
+      var maybe = S.parseDate('2001-02-03T04:05:06Z');
+      eq(maybe.constructor, S.Just);
+      eq(S.fromMaybe(null, maybe).constructor, Date);
+      eq(S.fromMaybe(null, maybe).getFullYear(), 2001);
+    });
+
+    it('returns a Nothing when applied to an invalid date string', function() {
+      var maybe = S.parseDate('today');
+      eq(maybe.constructor, S.Nothing);
+    });
+
+  });
+
   describe('parseFloat', function() {
 
     it('returns a Maybe', function() {
Repository: plaid/sanctuary
Pull request #9 (2015-02-12 07:08:55)

list: add S.find
Similar to [`R.find`][1] but uses Maybe to encode success/failure, rather than relying on null/undefined.


[1]: http://ramdajs.com/docs/#find



Patch:
diff --git a/index.js b/index.js
index 55d89b3..225fbfa 100644
--- a/index.js
+++ b/index.js
@@ -228,6 +228,16 @@
     return xs.length > 0 ? Just(slice_.call(xs, 0, -1)) : Nothing();
   };
 
+  //  find :: (a -> Boolean) -> [a] -> Maybe a
+  var find = curry(function(pred, xs) {
+    for (var idx = 0, len = xs.length; idx < len; idx += 1) {
+      if (pred(xs[idx])) {
+        return Just(xs[idx]);
+      }
+    }
+    return Nothing();
+  });
+
   //  object  ////////////////////////////////////////////////////////////////
 
   //  get :: String -> Object -> Maybe *
@@ -270,6 +280,7 @@
     at: at,
     either: either,
     encase: encase,
+    find: find,
     get: get,
     head: head,
     init: init,


Test patch:
diff --git a/test/index.js b/test/index.js
index 88793a0..da79f9f 100644
--- a/test/index.js
+++ b/test/index.js
@@ -478,6 +478,28 @@ describe('list', function() {
 
   });
 
+  describe('find', function() {
+
+    var T = function() { return true; };
+    var F = function() { return false; };
+
+    it('returns Just the first element satisfying the predicate', function() {
+      assert(S.find(T, [null]).equals(S.Just(null)));
+      assert(S.find(function(n) { return n >= 0; }, [-1, 0, 1])
+             .equals(S.Just(0)));
+    });
+
+    it('returns a Nothing if no element satisfies the predicate', function() {
+      assert(S.find(T, []).equals(S.Nothing()));
+      assert(S.find(F, [1, 2, 3]).equals(S.Nothing()));
+    });
+
+    it('is curried', function() {
+      assert(S.find(T)([null]).equals(S.Just(null)));
+    });
+
+  });
+
 });
 
 describe('object', function() {
Repository: plaid/sanctuary
Pull request #17 (2015-04-21 02:11:39)

combinator: add S.K
This is the (`R.always`) implementation suggested by @aaditmshah in https://github.com/ramda/ramda/issues/732#issuecomment-70383334. It may be too strict for Ramda, but it feels right at home here.



Patch:
diff --git a/index.js b/index.js
index 1525479..3c406b3 100644
--- a/index.js
+++ b/index.js
@@ -60,6 +60,13 @@
     });
   };
 
+  //  combinator  ////////////////////////////////////////////////////////////
+
+  //  K :: a -> b -> a
+  var K = curry(function(x, y) {  // jshint ignore:line
+    return x;
+  });
+
   //  maybe  /////////////////////////////////////////////////////////////////
 
   function Maybe() {
@@ -343,6 +350,7 @@
   var sanctuary = {
     Either: Either,
     Just: Just,
+    K: K,
     Left: Left,
     Maybe: Maybe,
     Nothing: Nothing,


Test patch:
diff --git a/test/index.js b/test/index.js
index d14e3b7..1485e46 100644
--- a/test/index.js
+++ b/test/index.js
@@ -28,6 +28,29 @@ var length = function(xs) { return xs.length; };
 var square = function(n) { return n * n; };
 
 
+describe('combinator', function() {
+
+  describe('K', function() {
+
+    it('is a binary function', function() {
+      eq(typeof S.K, 'function');
+      eq(S.K.length, 2);
+    });
+
+    it('returns its first argument', function() {
+      eq(S.K(21, []), 21);
+      eq(S.K(42, null), 42);
+      eq(S.K(84, undefined), 84);
+    });
+
+    it('is curried', function() {
+      eq(S.K(42)(null), 42);
+    });
+
+  });
+
+});
+
 describe('maybe', function() {
 
   describe('Maybe', function() {
Repository: plaid/sanctuary
Pull request #60 (2015-06-19 20:25:39)

handle new Number(-0) in S.slice, S.take, and S.drop
My first attempt was `R.pipe(Number, R.equals(-0))`, but this evaluates true when applied to `'-0'`.



Patch:
diff --git a/index.js b/index.js
index 95543ae..8ec7b7c 100644
--- a/index.js
+++ b/index.js
@@ -147,7 +147,8 @@
   };
 
   //  negativeZero :: a -> Boolean
-  var negativeZero = R.identical(-0);
+  var negativeZero = R.either(R.equals(-0),
+                              R.equals(new Number(-0)));  // jshint ignore:line
 
   var self = function() { return this; };
 


Test patch:
diff --git a/test/index.js b/test/index.js
index 035cb3d..cfeb609 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1357,6 +1357,10 @@ describe('list', function() {
     it('accepts -0 as the position half a step beyond the last index', function() {
       eq(S.slice(-0, 5, [1, 2, 3, 4, 5]), S.Just([]));
       eq(S.slice(2, -0, [1, 2, 3, 4, 5]), S.Just([3, 4, 5]));
+      // jshint -W053
+      eq(S.slice(new Number(-0), 5, [1, 2, 3, 4, 5]), S.Just([]));
+      eq(S.slice(2, new Number(-0), [1, 2, 3, 4, 5]), S.Just([3, 4, 5]));
+      // jshint +W053
     });
 
     it('returns a Just with the whole list', function() {
@@ -1468,6 +1472,9 @@ describe('list', function() {
       eq(S.take(-1, ['a', 'b', 'c', 'd', 'e']), S.Nothing());
       eq(S.take(-0, 'abcdefg'), S.Nothing());
       eq(S.take(-1, 'abcde'), S.Nothing());
+      // jshint -W053
+      eq(S.take(new Number(-0), ['a', 'b', 'c', 'd', 'e']), S.Nothing());
+      // jshint +W053
     });
 
     it('returns an empty collection if n is 0', function() {
@@ -1515,6 +1522,9 @@ describe('list', function() {
       eq(S.drop(-0, ['a', 'b', 'c', 'd', 'e']), S.Nothing());
       eq(S.drop(-3, 'abcde'), S.Nothing());
       eq(S.drop(-0, 'abcde'), S.Nothing());
+      // jshint -W053
+      eq(S.drop(new Number(-0), ['a', 'b', 'c', 'd', 'e']), S.Nothing());
+      // jshint +W053
     });
 
     it('returns an empty collection if n is equal to collection length', function() {
Repository: plaid/sanctuary
Pull request #76 (2015-09-04 05:55:15)

add maybeToEither
I basically just followed the `either` tests except for the 'is curried' part, as I noticed it was quite extensive but none of the other 'is curried' tests were.

I decided against including "eitherIfElse" for now. I pretty much only created it because it seemed like a decent idea and you can use it to define `maybeToEither`. If you really like the idea of, I'm happy to submit a PR, but I figured I'd just let it hang out in my code for a while and see how much I actually use it.

davidchambers: Very nice!

> [I'll let "eitherIfElse"] hang out in my code for a while and see how much I actually use it.

Good idea. :)


Patch:
diff --git a/index.js b/index.js
index fb5f400..fced8a6 100644
--- a/index.js
+++ b/index.js
@@ -972,6 +972,24 @@
     return either instanceof Left ? l(either.value) : r(either.value);
   });
 
+  //# maybeToEither :: a -> Maybe b -> Either a b
+  //.
+  //. Takes a value of any type and a Maybe, and returns an Either.
+  //. If the second argument is a Nothing, a Left containing the first
+  //. argument is returned. If the second argument is a Just, a Right
+  //. containing the Just's value is returned.
+  //.
+  //. ```javascript
+  //. > S.maybeToEither('Expecting an integer', S.parseInt(10, 'xyz'))
+  //. Left("Expecting an integer")
+  //.
+  //. > S.maybeToEither('Expecting an integer', S.parseInt(10, '42'))
+  //. Right(42)
+  //. ```
+  S.maybeToEither = def('maybeToEither', [a, Maybe], function(x, maybe) {
+    return maybe instanceof Nothing ? Left(x) : Right(maybe.value);
+  });
+
   //. ### Control
 
   var methodMissing = format('{repr} does not have {} {quote} method');


Test patch:
diff --git a/test/index.js b/test/index.js
index c3ebef9..7c529c9 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1163,6 +1163,36 @@ describe('either', function() {
 
   });
 
+  describe('maybeToEither', function() {
+
+    it('is a binary function', function() {
+      eq(typeof S.either, 'function');
+      eq(S.maybeToEither.length, 2);
+    });
+
+    it('type checks its arguments', function() {
+      assert.throws(function() { S.maybeToEither('left', 1); },
+                    errorEq(TypeError,
+                            '‘maybeToEither’ requires a value of type Maybe ' +
+                            'as its second argument; received 1'));
+    });
+
+    it('returns a Left of its first argument when the second is Nothing', function() {
+      eq(S.maybeToEither('error msg', S.Nothing()), S.Left('error msg'));
+    });
+
+    it('returns a Right of the value contained in the Just ' +
+       'when the second argument is a Just', function() {
+      eq(S.maybeToEither('error msg', S.Just(42)), S.Right(42));
+    });
+
+    it('is curried', function() {
+      eq(S.maybeToEither(0).length, 1);
+      eq(S.maybeToEither(0)(S.Just(42)), S.Right(42));
+    });
+
+  });
+
 });
 
 describe('control', function() {
Repository: plaid/sanctuary
Pull request #90 (2015-09-18 19:57:51)

combinator: add S.I
Ramda provides [`R.identity`][1], of course, but `S.I` is much shorter:

```javascript
S.encaseEither(R.identity, JSON.parse)
```

```javascript
S.encaseEither(S.I, JSON.parse)
```

Since we already provide `S.K`, it seems more fitting to name this function `I` rather than `id`.


[1]: http://ramdajs.com/docs/#identity



Patch:
diff --git a/index.js b/index.js
index f0b9325..9a05964 100644
--- a/index.js
+++ b/index.js
@@ -289,6 +289,17 @@
 
   //. ### Combinator
 
+  //# I :: a -> a
+  //.
+  //. The I combinator. Returns its argument. Equivalent to Haskell's `id`
+  //. function.
+  //.
+  //. ```javascript
+  //. > S.I('foo')
+  //. "foo"
+  //. ```
+  S.I = def('I', [a], function(x) { return x; });
+
   //# K :: a -> b -> a
   //.
   //. The K combinator. Takes two values and returns the first. Equivalent to


Test patch:
diff --git a/test/index.js b/test/index.js
index e1b45b5..2c40d03 100644
--- a/test/index.js
+++ b/test/index.js
@@ -143,6 +143,19 @@ describe('classify', function() {
 
 describe('combinator', function() {
 
+  describe('I', function() {
+
+    it('is a unary function', function() {
+      eq(typeof S.I, 'function');
+      eq(S.I.length, 1);
+    });
+
+    it('returns its argument', function() {
+      eq(S.I([1, 2, 3]), [1, 2, 3]);
+    });
+
+  });
+
   describe('K', function() {
 
     it('is a binary function', function() {
Repository: immerjs/immer
Pull request #630 (2020-06-22 12:22:22)

Map: new map key not added if value is undefined
Fix for #627 


Patch:
diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md
index 9963bb6..51f8e64 100644
--- a/.github/ISSUE_TEMPLATE/question.md
+++ b/.github/ISSUE_TEMPLATE/question.md
@@ -10,7 +10,7 @@ A clear and concise description of what the question is. In general we recommend
 
 ## Link to repro
 
-Please provide a [CodeSandbox demo](https://codesandbox.io/s/immer-sandbox-6wijw) to clarify your question if possible. Typically, questions without minimal codesandbox demo won't be answered.
+Please provide a [CodeSandbox demo](https://codesandbox.io/s/immer-sandbox-6wijw) to clarify your question if possible.
 
 ## Environment
 
diff --git a/src/plugins/mapset.ts b/src/plugins/mapset.ts
index 8e5b111..8bb2d09 100644
--- a/src/plugins/mapset.ts
+++ b/src/plugins/mapset.ts
@@ -80,7 +80,7 @@ export function enableMapSet() {
 		p.set = function(key: any, value: any) {
 			const state: MapState = this[DRAFT_STATE]
 			assertUnrevoked(state)
-			if (latest(state).get(key) !== value) {
+			if (!latest(state).has(key) || latest(state).get(key) !== value) {
 				prepareMapCopy(state)
 				markChanged(state)
 				state.assigned_!.set(key, true)


Test patch:
diff --git a/__tests__/map-set.js b/__tests__/map-set.js
index 7ba2592..faa4680 100644
--- a/__tests__/map-set.js
+++ b/__tests__/map-set.js
@@ -235,5 +235,14 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
 			})
 			expect(Array.from(set).sort()).toEqual([1, 2, 3])
 		})
+
+		test("#627 - new map key with value=undefined", () => {
+			const map = new Map()
+			const map1 = produce(map, draft => {
+				draft.set("key", undefined)
+			})
+			expect(map1.has("key")).toBe(true)
+			expect(map1.get("key")).toBe(undefined)
+		})
 	})
 }
Repository: immerjs/immer
Pull request #690 (2020-10-21 15:39:21)

Proxy: Ignore setting a reference to itself


Patch:
diff --git a/src/core/proxy.ts b/src/core/proxy.ts
index 2469d73..bfa8049 100644
--- a/src/core/proxy.ts
+++ b/src/core/proxy.ts
@@ -157,6 +157,9 @@ export const objectTraps: ProxyHandler<ProxyState> = {
 			prepareCopy(state)
 			markChanged(state)
 		}
+
+		if (state.copy_![prop] === value && typeof value !== "number") return true
+
 		// @ts-ignore
 		state.copy_![prop] = value
 		state.assigned_[prop] = true


Test patch:
diff --git a/__tests__/patch.js b/__tests__/patch.js
index 7baba6e..3cdf4bb 100644
--- a/__tests__/patch.js
+++ b/__tests__/patch.js
@@ -1147,3 +1147,24 @@ test("#676 patching Date objects", () => {
 	)
 	expect(rebuilt.date).toEqual(new Date(2020, 10, 10, 8, 8, 8, 3))
 })
+
+test("#648 assigning object to itself should not change patches", () => {
+	const input = {
+		obj: {
+			value: 200
+		}
+	}
+
+	const [nextState, patches] = produceWithPatches(input, draft => {
+		draft.obj.value = 1
+		draft.obj = draft.obj
+	})
+
+	expect(patches).toEqual([
+		{
+			op: "replace",
+			path: ["obj", "value"],
+			value: 1
+		}
+	])
+})
Repository: rclone/rclone
Pull request #7232 (2023-08-16 12:10:44)

fs: Fix transferTime not being set in JSON logs
#### What is the purpose of this change?
transferTime is always 0 in JSON logs (and anything else that uses `RemoteStats()`.)

This was unintentionally broken in https://github.com/rclone/rclone/commit/04aa6969a47516643cdf9084f9cdeae320a3bb81#diff-6a0766bcecac2744ee5f6050fdd22077ff967a44fb9df9fc2711130fcde3230bL279

#### Was the change discussed in an issue or in the forum before?

No - found while looking at JSON logs when using rclone

#### Testing

- Added unit test
- Tested locally and confirmed that --use-json-log shows transferTime counting in seconds as a float

#### Checklist

- [x] I have read the [contribution guidelines](https://github.com/rclone/rclone/blob/master/CONTRIBUTING.md#submitting-a-new-feature-or-bug-fix).
- [x] I have added tests for all changes in this PR if appropriate.
- [x] I have added documentation for the changes if appropriate. // none needed
- [x] All commit messages are in [house style](https://github.com/rclone/rclone/blob/master/CONTRIBUTING.md#commit-messages).
- [x] I'm done, this Pull Request is ready for review :-)



Patch:
diff --git a/fs/accounting/stats.go b/fs/accounting/stats.go
index 0faa74180..24c9bcda1 100644
--- a/fs/accounting/stats.go
+++ b/fs/accounting/stats.go
@@ -313,6 +313,8 @@ func (s *StatsInfo) calculateTransferStats() (ts transferStats) {
 	// we take it off here to avoid double counting
 	ts.totalBytes = s.transferQueueSize + s.bytes + transferringBytesTotal - transferringBytesDone
 	ts.speed = s.average.speed
+	dt := s.totalDuration()
+	ts.transferTime = dt.Seconds()
 
 	return ts
 }


Test patch:
diff --git a/fs/accounting/stats_test.go b/fs/accounting/stats_test.go
index 58e8150bd..773311824 100644
--- a/fs/accounting/stats_test.go
+++ b/fs/accounting/stats_test.go
@@ -251,6 +251,28 @@ func TestStatsTotalDuration(t *testing.T) {
 	})
 }
 
+func TestRemoteStats(t *testing.T) {
+	ctx := context.Background()
+	startTime := time.Now()
+	time1 := startTime.Add(-40 * time.Second)
+	time2 := time1.Add(10 * time.Second)
+
+	t.Run("Single completed transfer", func(t *testing.T) {
+		s := NewStats(ctx)
+		tr1 := &Transfer{
+			startedAt:   time1,
+			completedAt: time2,
+		}
+		s.AddTransfer(tr1)
+		time.Sleep(time.Millisecond)
+		rs, err := s.RemoteStats()
+
+		require.NoError(t, err)
+		assert.Equal(t, float64(10), rs["transferTime"])
+		assert.Greater(t, rs["elapsedTime"], float64(0))
+	})
+}
+
 // make time ranges from string description for testing
 func makeTimeRanges(t *testing.T, in []string) timeRanges {
 	trs := make(timeRanges, len(in))