You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "paulk-asert (via GitHub)" <gi...@apache.org> on 2026/05/22 14:08:05 UTC
[PR] GROOVY-12031: Provide a DGM#takeIf method [groovy]
paulk-asert opened a new pull request, #2553:
URL: https://github.com/apache/groovy/pull/2553
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-12031: Provide a DGM#takeIf method [groovy]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2553:
URL: https://github.com/apache/groovy/pull/2553#issuecomment-4522680041
## 🚨 TestLens detected 1 failed test 🚨
Here is what you can do:
1) Inspect the test failures carefully.
2) If you are convinced that some of the tests are flaky, you can mute them below.
3) Finally, trigger a rerun by checking the rerun checkbox.
### Test Summary
| Check | Project/Task | Test | Runs |
|---|---|---|---|
| [Build and test / lts \(21, ubuntu-latest\)](https://github.com/apache/groovy/actions/runs/26311428988/job/77460841312?pr=2553) | :groovy-groovysh:test | HelpCommandTest > helpListsKnownCommands\(\) | ❌ |
🏷️ Commit: af0f1b9fa2f365e9404318300b80dfda09614755
▶️ Tests: 16945 executed
🟡 Checks: 3/28 completed
### Test Failures
<details>
<summary><strong>HelpCommandTest > helpListsKnownCommands()</strong> (:groovy-groovysh:test in <a href="https://github.com/apache/groovy/actions/runs/26311428988/job/77460841312?pr=2553">Build and test / lts (21, ubuntu-latest)</a>)</summary>
```
Assertion failed:
assert out.contains('show')
| |
| false
'[?2027$p[c [34;1mSystem[0m:\r\n [1m/exit[0m \r\n [1m/help[0m \r\n '
at org.codehaus.groovy.runtime.InvokerHelper.createAssertError(InvokerHelper.java:400)
at org.apache.groovy.groovysh.commands.HelpCommandTest.helpListsKnownCommands(HelpCommandTest.groovy:44)
```
</details>
### Muted Tests
> [!NOTE]
> Checks are currently running using the configuration below.
Select tests to mute in this pull request:
🔲 HelpCommandTest > helpListsKnownCommands\(\) <!-- uniqueId=[engine:junit-jupiter]/[class:org.apache.groovy.groovysh.commands.HelpCommandTest]/[method:helpListsKnownCommands()] -->
Reuse successful test results:
🔲 ♻️ Only rerun the tests that failed or were muted before
Click the checkbox to trigger a rerun:
🔲 **Rerun jobs**
---
_Learn more about TestLens at [testlens.app](https://testlens.app)._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-12031: Provide a DGM#takeIf method [groovy]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2553:
URL: https://github.com/apache/groovy/pull/2553#issuecomment-4519715034
## [Codecov](https://app.codecov.io/gh/apache/groovy/pull/2553?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 68.1775%. Comparing base ([`5318145`](https://app.codecov.io/gh/apache/groovy/commit/53181454e08716af1fb76927215775fb75084f56?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`c25b60c`](https://app.codecov.io/gh/apache/groovy/commit/c25b60c39c193668f5d256060badfcf71a9da14f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/groovy/pull/2553?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #2553 +/- ##
==================================================
- Coverage 68.1844% 68.1775% -0.0069%
+ Complexity 33086 33085 -1
==================================================
Files 1508 1508
Lines 126130 126131 +1
Branches 22878 22878
==================================================
- Hits 86001 85993 -8
- Misses 32490 32495 +5
- Partials 7639 7643 +4
```
| [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2553?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [.../codehaus/groovy/runtime/DefaultGroovyMethods.java](https://app.codecov.io/gh/apache/groovy/pull/2553?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fruntime%2FDefaultGroovyMethods.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3J1bnRpbWUvRGVmYXVsdEdyb292eU1ldGhvZHMuamF2YQ==) | `75.0982% <100.0000%> (+0.0070%)` | :arrow_up: |
... and [7 files with indirect coverage changes](https://app.codecov.io/gh/apache/groovy/pull/2553/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-12031: Provide a DGM#takeIf method [groovy]
Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2553:
URL: https://github.com/apache/groovy/pull/2553#issuecomment-4519803537
## ✅ All tests passed ✅
🏷️ Commit: c25b60c39c193668f5d256060badfcf71a9da14f
▶️ Tests: 99672 executed
⚪️ Checks: 28/28 completed
---
_Learn more about TestLens at [testlens.app](https://testlens.app)._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-12031: Provide a DGM#takeIf method [groovy]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2553:
URL: https://github.com/apache/groovy/pull/2553#discussion_r3291070512
##########
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java:
##########
@@ -15068,6 +15068,33 @@ public void remove() {
}
}
+ //--------------------------------------------------------------------------
+ // takeIf
+
+ /**
+ * Returns this object if it satisfies the given predicate, or {@code null}
+ * otherwise. Useful for guarding a value through a chain, particularly with
+ * the Elvis or safe-navigation operators.
+ * <pre class="language-groovy groovyTestCase">
+ * assert 'hello'.takeIf{ it.startsWith('h') } == 'hello'
+ * assert 'hello'.takeIf{ it.startsWith('z') } == null
+ * assert ('input'.takeIf{ it.startsWith('http') } ?: "https://input") == 'https://input'
+ * assert [1, 2, 3].takeIf{ !it.isEmpty() }?.size() == 3
+ * assert [].takeIf{ !it.isEmpty() }?.size() == null
+ * </pre>
+ * The predicate is invoked with the receiver as its argument; the receiver
+ * is not used as a delegate. The receiver is passed through to the predicate
+ * unchanged, including when it is {@code null}.
+ *
+ * @param self the object to test
+ * @param condition the predicate applied to {@code self}
+ * @return {@code self} if {@code condition.test(self)} is {@code true}, otherwise {@code null}
+ * @since 6.0.0
+ */
+ public static <T> T takeIf(T self, Predicate<T> condition) {
+ return condition.test(self) ? self : null;
Review Comment:
The parameter type `Predicate<T>` is unnecessarily invariant for a general-purpose GDK method. Using `Predicate<? super T>` makes the API more flexible (e.g., allows a `Predicate<Object>` to be used when `T` is a subtype) without changing behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-12031: Provide a DGM#takeIf method [groovy]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert merged PR #2553:
URL: https://github.com/apache/groovy/pull/2553
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org