PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: sanctuary-js/sanctuary (js)

Issue:
Add S.when and S.unless
Create versions of [R.when](http://ramdajs.com/0.23.0/docs/#when) and [R.unless](http://ramdajs.com/0.23.0/docs/#unless).

Pull request:
logic: add S.when and S.unless
Closes #347

Patch:
diff --git a/index.js b/index.js
index 52d5f30..442c0d2 100644
--- a/index.js
+++ b/index.js
@@ -2613,6 +2613,42 @@
   }
   S.ifElse = def('ifElse', {}, [Pred(a), Fn(a, b), Fn(a, b), a, b], ifElse);
 
+  //# when :: (a -> Boolean) -> (a -> a) -> a -> a
+  //.
+  //. Takes a unary predicate, a unary function, and a value of any type, and
+  //. returns the result of applying the function to the value if the value
+  //. satisfies the predicate; the value otherwise.
+  //.
+  //. ```javascript
+  //. > S.when(x => x >= 0, Math.sqrt, 16)
+  //. 4
+  //.
+  //. > S.when(x => x >= 0, Math.sqrt, -1)
+  //. -1
+  //. ```
+  function when(pred, f, x) {
+    return ifElse(pred, f, I, x);
+  }
+  S.when = def('when', {}, [Pred(a), Fn(a, a), a, a], when);
+
+  //# unless :: (a -> Boolean) -> (a -> a) -> a -> a
+  //.
+  //. Takes a unary predicate, a unary function, and a value of any type, and
+  //. returns the result of applying the function to the value if the value
+  //. does not satisfy the predicate; the value otherwise.
+  //.
+  //. ```javascript
+  //. > S.unless(x => x < 0, Math.sqrt, 16)
+  //. 4
+  //.
+  //. > S.unless(x => x < 0, Math.sqrt, -1)
+  //. -1
+  //. ```
+  function unless(pred, f, x) {
+    return ifElse(pred, I, f, x);
+  }
+  S.unless = def('unless', {}, [Pred(a), Fn(a, a), a, a], unless);
+
   //# allPass :: Array (a -> Boolean) -> a -> Boolean
   //.
   //. Takes an array of unary predicates and a value of any type


Test patch:
diff --git a/test/unless.js b/test/unless.js
new file mode 100644
index 0000000..93f5ba4
--- /dev/null
+++ b/test/unless.js
@@ -0,0 +1,19 @@
+'use strict';
+
+var S = require('..');
+
+var eq = require('./internal/eq');
+
+
+test('unless', function() {
+
+  eq(typeof S.unless, 'function');
+  eq(S.unless.length, 3);
+  eq(S.unless.toString(), 'unless :: (a -> Boolean) -> (a -> a) -> a -> a');
+
+  function lt0(x) { return x < 0; }
+
+  eq(S.unless(lt0, Math.sqrt, 16), 4);
+  eq(S.unless(lt0, Math.sqrt, -1), -1);
+
+});
diff --git a/test/when.js b/test/when.js
new file mode 100644
index 0000000..ee59419
--- /dev/null
+++ b/test/when.js
@@ -0,0 +1,19 @@
+'use strict';
+
+var S = require('..');
+
+var eq = require('./internal/eq');
+
+
+test('when', function() {
+
+  eq(typeof S.when, 'function');
+  eq(S.when.length, 3);
+  eq(S.when.toString(), 'when :: (a -> Boolean) -> (a -> a) -> a -> a');
+
+  function gte0(x) { return x >= 0; }
+
+  eq(S.when(gte0, Math.sqrt, 16), 4);
+  eq(S.when(gte0, Math.sqrt, -1), -1);
+
+});
Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 40
Good morning! Here's your coding interview problem for today.

This problem was asked by Google.

Given an array of integers where every integer occurs three times except for one integer, which only occurs once, find and return the non-duplicated integer.

For example, given [6, 1, 3, 3, 3, 6, 6], return 1. Given [13, 19, 13, 13], return 19.

Do this in O(N) time and O(1) space.

Pull request:
Day40
Resolves #87.

Patch:
diff --git a/README.md b/README.md
index 4ec99d9..e1c7e73 100644
--- a/README.md
+++ b/README.md
@@ -50,3 +50,4 @@ problems from
 * [Day 36](https://github.com/vaskoz/dailycodingproblem-go/issues/79)
 * [Day 37](https://github.com/vaskoz/dailycodingproblem-go/issues/81)
 * [Day 38](https://github.com/vaskoz/dailycodingproblem-go/issues/83)
+* [Day 40](https://github.com/vaskoz/dailycodingproblem-go/issues/87)
diff --git a/day40/problem.go b/day40/problem.go
new file mode 100644
index 0000000..b05344c
--- /dev/null
+++ b/day40/problem.go
@@ -0,0 +1,33 @@
+package day40
+
+// FindOnce returns the number that appears only once in a list where
+// other numbers appear 3 times.
+// Runs in O(N) time and O(1) space.
+func FindOnce(nums []int) int {
+	var ones, twos int
+	for _, v := range nums {
+		twos |= ones & v
+		ones ^= v
+		not := ^(ones & twos)
+		ones &= not
+		twos &= not
+	}
+	return ones
+}
+
+// FindOnceMap uses a map to find the non-duplicated value.
+// Runs in O(N) and O(N) space
+func FindOnceMap(nums []int) int {
+	counts := make(map[int]int)
+	for _, v := range nums {
+		counts[v]++
+	}
+	var result int
+	for k, v := range counts {
+		if v == 1 {
+			result = k
+			break
+		}
+	}
+	return result
+}


Test patch:
diff --git a/day40/problem_test.go b/day40/problem_test.go
new file mode 100644
index 0000000..e4cc156
--- /dev/null
+++ b/day40/problem_test.go
@@ -0,0 +1,45 @@
+package day40
+
+import "testing"
+
+var testcases = []struct {
+	input    []int
+	expected int
+}{
+	{[]int{6, 1, 3, 3, 3, 6, 6}, 1},
+	{[]int{13, 19, 13, 13}, 19},
+}
+
+func TestFindOnce(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := FindOnce(tc.input); tc.expected != result {
+			t.Errorf("Expected %v got %v", tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkFindOnce(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			FindOnce(tc.input)
+		}
+	}
+}
+
+func TestFindOnceMap(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := FindOnceMap(tc.input); tc.expected != result {
+			t.Errorf("Expected %v got %v", tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkFindOnceMap(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			FindOnceMap(tc.input)
+		}
+	}
+}
Repository: laravel/framework (php)

Issue:
Calling `forceCreate()` on a MorphMany relation doesn't includes morph type
<!-- DO NOT THROW THIS AWAY -->
<!-- Fill out the FULL versions with patch versions -->

- Laravel Version: 9.17
- PHP Version: 8.0.23
- Database Driver & Version: N/A

### Description:

When using `forceCreate()` on a morph relation (`morphOne|morphMany`), the morph type column is not added.

```
$post->comments()->forceCreate(['body' => 'Cool article']);
```

This behavior is realated to #42281.

### Steps To Reproduce:

```php
class Post extends Model
{
    public $fillable = ['*'];
    public function comments() { return $this->morphMany(Comment::class, 'commentable'); }
}

class Comment extends Model
{
    public function commentable() { return $this->morphTo(); }
}

$post = Post::create(['body' => 'Hello world!']);

$post->comments()->forceCreate(['body' => 'Cool article']);

// Illuminate\Database\QueryException : 
//   SQLSTATE[23000]: 
//     Integrity constraint violation: 
//       19 NOT NULL constraint failed: comments.commentable_type
//       ...
```

Pull request:
Fixed bug on forceCreate on a MorphMay relationship  not including morph type
Fixes #42796

`forceCreate` was not including the morph type on the attributes sent to create the related model. The  forceCreate method has been overrided to include the morph type on the attributes before passing the call to its parent.

This should solve the #42796 issue.


Patch:
diff --git a/src/Illuminate/Database/Eloquent/Relations/MorphMany.php b/src/Illuminate/Database/Eloquent/Relations/MorphMany.php
index 12b0650263..6869e5bacd 100755
--- a/src/Illuminate/Database/Eloquent/Relations/MorphMany.php
+++ b/src/Illuminate/Database/Eloquent/Relations/MorphMany.php
@@ -46,4 +46,16 @@ public function match(array $models, Collection $results, $relation)
     {
         return $this->matchMany($models, $results, $relation);
     }
+
+    /**
+     * Create a new instance of the related model. Allow mass-assignment.
+     *
+     * @param  array  $attributes
+     * @return \Illuminate\Database\Eloquent\Model
+     */
+    public function forceCreate(array $attributes = []) 
+    {
+        $attributes[$this->getMorphType()] = $this->morphClass;
+        parent::forceCreate($attributes);
+    }
 }


Test patch:
diff --git a/tests/Database/DatabaseEloquentMorphOneOfManyTest.php b/tests/Database/DatabaseEloquentMorphOneOfManyTest.php
index 4d98d120ef..9a8e70f4c7 100644
--- a/tests/Database/DatabaseEloquentMorphOneOfManyTest.php
+++ b/tests/Database/DatabaseEloquentMorphOneOfManyTest.php
@@ -94,6 +94,15 @@ public function testMorphType()
         $this->assertSame('active', $product->current_state->state);
     }
 
+    public function testForceCreateMorphType()
+    {
+        $product = MorphOneOfManyTestProduct::create();
+        $product->states()->forceCreate([
+            'state' => 'active',
+        ]);
+        $this->assertSame(MorphOneOfManyTestProduct::class, $product->current_state->stateful_type);
+    }
+
     public function testExists()
     {
         $product = MorphOneOfManyTestProduct::create();
Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 248
Good morning! Here's your coding interview problem for today.

This problem was asked by Nvidia.

Find the maximum of two numbers without using any if-else statements, branching, or direct comparisons.

Pull request:
Day248
Resolves #512.

Patch:
diff --git a/README.md b/README.md
index 660b03a..2a243fd 100644
--- a/README.md
+++ b/README.md
@@ -259,3 +259,4 @@ problems from
 * [Day 245](https://github.com/vaskoz/dailycodingproblem-go/issues/506)
 * [Day 246](https://github.com/vaskoz/dailycodingproblem-go/issues/508)
 * [Day 247](https://github.com/vaskoz/dailycodingproblem-go/issues/510)
+* [Day 248](https://github.com/vaskoz/dailycodingproblem-go/issues/512)
diff --git a/day248/problem.go b/day248/problem.go
new file mode 100644
index 0000000..a7f60d3
--- /dev/null
+++ b/day248/problem.go
@@ -0,0 +1,27 @@
+package day248
+
+// MaxIf is a typical max function using an if branch.
+func MaxIf(a, b int64) int64 {
+	if a > b {
+		return a
+	}
+	return b
+}
+
+// MaxSubtractAndShift finds the max using subtraction
+// and right shifting.
+func MaxSubtractAndShift(a, b int64) int64 {
+	return a - ((a - b) & ((a - b) >> 63))
+}
+
+// MaxXor uses xor and branching to calculate the max.
+// Go requires if branching to convert a bool to an int64.
+// NOTE: No benefit here due to branching if, might as well use MaxIf.
+// Benchmark perf shows actually worse than MaxIf as expected.
+func MaxXor(a, b int64) int64 {
+	bit := int64(0)
+	if a < b {
+		bit = int64(-1)
+	}
+	return a ^ ((a ^ b) & bit)
+}


Test patch:
diff --git a/day248/problem_test.go b/day248/problem_test.go
new file mode 100644
index 0000000..60acc0d
--- /dev/null
+++ b/day248/problem_test.go
@@ -0,0 +1,64 @@
+package day248
+
+import "testing"
+
+// nolint
+var testcases = []struct {
+	a, b, max int64
+}{
+	{10, 20, 20},
+	{20, 1, 20},
+	{30, 2, 30},
+	{1, -2, 1},
+}
+
+func TestMaxIf(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if max := MaxIf(tc.a, tc.b); max != tc.max {
+			t.Errorf("Expected %v, got %v", tc.max, max)
+		}
+	}
+}
+
+func BenchmarkMaxIf(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			MaxIf(tc.a, tc.b)
+		}
+	}
+}
+
+func TestMaxSubtractAndShift(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if max := MaxSubtractAndShift(tc.a, tc.b); max != tc.max {
+			t.Errorf("Expected %v, got %v", tc.max, max)
+		}
+	}
+}
+
+func BenchmarkMaxSubtractAndShift(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			MaxSubtractAndShift(tc.a, tc.b)
+		}
+	}
+}
+
+func TestMaxXor(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if max := MaxXor(tc.a, tc.b); max != tc.max {
+			t.Errorf("Expected %v, got %v", tc.max, max)
+		}
+	}
+}
+
+func BenchmarkMaxXor(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			MaxXor(tc.a, tc.b)
+		}
+	}
+}
Repository: michalkvasnicak/aws-lambda-graphql (ts)

Issue:
Publishing to undefined topic breaks dynamoDB trigger
When you try to publish subscription message like this
```await pubSub.publish(undefined, payload)```
It will allow to publish such message however lambda trigger will throw this error:

> ExpressionAttributeValues must not be empty

Moreover because trigger lambda failed it will try to invoke it again with same parameter creating a loop which is possible to break only when you delete your dynamoDB trigger

I think `event` property should be part of composite key on dynamoDB Events table, and we should throw an error in PubSub when trying to publish event without a topic

Pull request:
Do not allow publishing event with empty name
Closes #49 

Patch:
diff --git a/packages/aws-lambda-graphql/src/PubSub.ts b/packages/aws-lambda-graphql/src/PubSub.ts
index 038939b..dc9167f 100644
--- a/packages/aws-lambda-graphql/src/PubSub.ts
+++ b/packages/aws-lambda-graphql/src/PubSub.ts
@@ -1,3 +1,4 @@
+import * as assert from 'assert';
 import { IEventStore, OperationRequest, SubcribeResolveFn } from './types';
 
 type Options = {
@@ -43,6 +44,11 @@ class PubSub {
    * So you should not expect to fire in same process
    */
   publish = async (eventName: string, payload: any) => {
+    assert.ok(
+      typeof eventName === 'string' && eventName !== '',
+      'Event name cannot be empty',
+    );
+
     await this.eventStore.publish({
       payload: JSON.stringify(payload),
       event: eventName,


Test patch:
diff --git a/packages/aws-lambda-graphql/src/__tests__/PubSub.test.ts b/packages/aws-lambda-graphql/src/__tests__/PubSub.test.ts
index 5f711d0..a5a808a 100644
--- a/packages/aws-lambda-graphql/src/__tests__/PubSub.test.ts
+++ b/packages/aws-lambda-graphql/src/__tests__/PubSub.test.ts
@@ -65,6 +65,20 @@ describe('PubSub', () => {
   });
 
   describe('publish', () => {
+    it('does not allow to publish event with empty name', async () => {
+      const ps = new PubSub({ eventStore: eventStore as any });
+
+      await expect(ps.publish(undefined, {})).rejects.toThrowError(
+        'Event name cannot be empty',
+      );
+      await expect(ps.publish(null, {})).rejects.toThrowError(
+        'Event name cannot be empty',
+      );
+      await expect(ps.publish('', {})).rejects.toThrowError(
+        'Event name cannot be empty',
+      );
+    });
+
     it('works correctly', async () => {
       const ps = new PubSub({ eventStore: eventStore as any });