PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: ProcessMaker/nayra (php)

Issue:
Add findFirst method to collections
As a developer I would like to get the first element of a collection that matches a condition, so I can work with that element.

To do that, add the following implementation to `CollectionInterface`:

```
    /**
     * Find first element of the collection that match the $condition.
     *
     * @param callable $condition
     *
     * @return mixed
     */
    public function findFirst(callable $condition);
```


Pull request:
Resolves #174 Implement Collection::findFirst
This PR includes:

- Implementation of Collection::findFirst
- Unit tests for Collection::findFirst


Patch:
diff --git a/src/ProcessMaker/Nayra/Bpmn/Collection.php b/src/ProcessMaker/Nayra/Bpmn/Collection.php
index 8b2bc1e..28fa266 100755
--- a/src/ProcessMaker/Nayra/Bpmn/Collection.php
+++ b/src/ProcessMaker/Nayra/Bpmn/Collection.php
@@ -57,6 +57,18 @@ class Collection implements CollectionInterface
         return new Collection(array_filter($this->items, $condition));
     }
 
+    /**
+     * Find first element of the collection that match the $condition.
+     *
+     * @param callable $condition
+     *
+     * @return mixed
+     */
+    public function findFirst(callable $condition)
+    {
+        return current(array_filter($this->items, $condition));
+    }
+
     /**
      * Add an element to the collection.
      *
diff --git a/src/ProcessMaker/Nayra/Contracts/Bpmn/CollectionInterface.php b/src/ProcessMaker/Nayra/Contracts/Bpmn/CollectionInterface.php
index 882ceec..874c273 100755
--- a/src/ProcessMaker/Nayra/Contracts/Bpmn/CollectionInterface.php
+++ b/src/ProcessMaker/Nayra/Contracts/Bpmn/CollectionInterface.php
@@ -28,6 +28,15 @@ interface CollectionInterface extends SeekableIterator
      */
     public function find($condition);
 
+    /**
+     * Find first element of the collection that match the $condition.
+     *
+     * @param callable $condition
+     *
+     * @return mixed
+     */
+    public function findFirst(callable $condition);
+
     /**
      * Add an element to the collection.
      *


Test patch:
diff --git a/tests/unit/ProcessMaker/Nayra/Bpmn/CollectionTest.php b/tests/unit/ProcessMaker/Nayra/Bpmn/CollectionTest.php
index f9aa064..84632ca 100755
--- a/tests/unit/ProcessMaker/Nayra/Bpmn/CollectionTest.php
+++ b/tests/unit/ProcessMaker/Nayra/Bpmn/CollectionTest.php
@@ -183,4 +183,18 @@ class CollectionTest extends TestCase
         $this->assertEquals(1, $this->object->key());
         $this->assertEquals(2, $this->object->current());
     }
+
+    /**
+     * Find first element of the collection that match the $condition.
+     *
+     */
+    public function testFindFirst()
+    {
+        $this->assertEquals(2, $this->object->findFirst(function ($item) {
+            return $item === 2;
+        }));
+        $this->assertEquals(1, $this->object->findFirst(function ($item) {
+            return $item % 2;
+        }));
+    }
 }
Repository: cloudwego/hertz (go)

Issue:
:sparkles: feat-request: errors support format
like: `errors.Newf`, `errors.NewPublicf`

Pull request:
feat: errors support format
#### What type of PR is this?

feat

#### Check the PR title.
- [x] This PR title match the format: \<type\>(optional scope): \<description\>
- [x] The description of this PR title is user-oriented and clear enough for others to understand.

#### Translate the PR title into Chinese.

支持`error`的格式化

#### More detail description for this PR(en: English/zh: Chinese).

en: Add three methods: `errors.Newf`, `errors.NewPublicf`, `errors.NewPrivatef` whit unit tests.

zh: 添加了三个方法：`errors.Newf`，`errors.NewPublicf`，`errors.NewPrivatef`，并补充了单元测试。

#### Which issue(s) this PR fixes:

Fixes #248 



Patch:
diff --git a/pkg/common/errors/errors.go b/pkg/common/errors/errors.go
index 38e90c9..d764c41 100644
--- a/pkg/common/errors/errors.go
+++ b/pkg/common/errors/errors.go
@@ -222,3 +222,15 @@ func NewPublic(err string) *Error {
 func NewPrivate(err string) *Error {
 	return New(errors.New(err), ErrorTypePrivate, nil)
 }
+
+func Newf(t ErrorType, meta interface{}, format string, v ...interface{}) *Error {
+	return New(fmt.Errorf(format, v...), t, meta)
+}
+
+func NewPublicf(format string, v ...interface{}) *Error {
+	return New(fmt.Errorf(format, v...), ErrorTypePublic, nil)
+}
+
+func NewPrivatef(format string, v ...interface{}) *Error {
+	return New(fmt.Errorf(format, v...), ErrorTypePrivate, nil)
+}


Test patch:
diff --git a/pkg/common/errors/errors_test.go b/pkg/common/errors/errors_test.go
index 1f54297..834b272 100644
--- a/pkg/common/errors/errors_test.go
+++ b/pkg/common/errors/errors_test.go
@@ -130,3 +130,12 @@ Error #03: third
 	assert.Nil(t, errs.JSON())
 	assert.DeepEqual(t, "", errs.String())
 }
+
+func TestErrorFormat(t *testing.T) {
+	err := Newf(ErrorTypeAny, nil, "caused by %s", "reason")
+	assert.DeepEqual(t, New(errors.New("caused by reason"), ErrorTypeAny, nil), err)
+	publicErr := NewPublicf("caused by %s", "reason")
+	assert.DeepEqual(t, New(errors.New("caused by reason"), ErrorTypePublic, nil), publicErr)
+	privateErr := NewPrivatef("caused by %s", "reason")
+	assert.DeepEqual(t, New(errors.New("caused by reason"), ErrorTypePrivate, nil), privateErr)
+}