-
Couldn't load subscription status.
- Fork 8
feat: Add utilities for working with functions #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughA new functional programming utility module is introduced, providing Dart extensions for piping, function composition, partial application, and tuple-based argument packing (for up to four parameters). The main library exports this module, and a comprehensive test suite is added to verify all new utilities. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Value
participant FunctionA
participant FunctionB
User->>Value: Provide input
Value->>FunctionA: Pipe (pipe extension)
FunctionA->>FunctionB: Compose (compose extension)
FunctionB-->>User: Output result
sequenceDiagram
participant User
participant FunctionN
participant Tuple
User->>FunctionN: Apply (partial application)
User->>Tuple: Pack arguments
Tuple->>FunctionN: Unpack (pack extension)
FunctionN-->>User: Output result
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #77 +/- ##
==========================================
+ Coverage 82.51% 82.61% +0.09%
==========================================
Files 81 82 +1
Lines 2522 2536 +14
Branches 1408 1422 +14
==========================================
+ Hits 2081 2095 +14
Misses 441 441 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
28c155c to
c7f046c
Compare
- pipe - compose - pack - apply
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
lib/src/util/functional.dart (1)
11-13: Consider removing redundant Apply1 extension.The Apply1 extension doesn't provide any functional benefit over calling the function directly. It simply wraps a normal function call without adding partial application capabilities.
Consider removing this extension:
-extension Apply1<T, R> on R Function(T) { - R apply(final T x) => this(x); -}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
lib/relic.dart(1 hunks)lib/src/util/functional.dart(1 hunks)test/util/functional_test.dart(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Verify Build (ubuntu-latest, 3.5.0)
🔇 Additional comments (9)
lib/src/util/functional.dart (4)
1-3: LGTM! Clean implementation of the pipe operator.The pipe extension correctly implements the functional programming pipe pattern, allowing for elegant method chaining.
5-8: LGTM! Correct function composition implementation.The compose extension properly implements function composition with the correct order of operations (inner function applied first, then outer function).
15-26: LGTM! Partial application extensions are well-implemented.The Apply2-4 extensions correctly implement partial application by fixing the first argument and returning functions that accept the remaining parameters.
29-45: LGTM! Pack extensions correctly implement tuple unpacking.The Pack extensions properly convert multi-parameter functions into tuple-accepting functions using Dart's tuple destructuring syntax.
lib/relic.dart (1)
29-29: LGTM! Functional utilities correctly exported.The export statement properly exposes the new functional programming utilities to library users following the established pattern.
test/util/functional_test.dart (4)
5-37: LGTM! Comprehensive pipe extension tests.The test cases effectively validate both single function piping and chained piping operations with clear arrange-act-assert structure.
39-79: LGTM! Thorough compose extension tests.The composition tests correctly validate both simple and complex function composition scenarios, ensuring proper order of operations.
81-163: LGTM! Complete coverage of apply extensions.The test suite comprehensively validates partial application for all supported arities (1-4), with correct assertions for the partially applied functions.
165-239: LGTM! Thorough pack extension tests.The pack tests effectively validate tuple unpacking functionality for all supported arities (1-4), confirming correct parameter mapping from tuples to function arguments.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
bf48ea0 to
e362193
Compare
Description
This PR introduces a set of functional programming utilities.
lib/src/util/functional.dart, has been added, which includes extension methods for:pipe: For chaining functions.compose: For composing functions.apply: For partial application of functions (supports 1 to 4 arguments).pack: For converting functions that take multiple arguments into functions that take a single tuple argument (supports 1 to 4 arguments).lib/relic.dartfile for easier access.This allows for more expressive handler composition in Relic.
Related Issues
Pre-Launch Checklist
Please ensure that your PR meets the following requirements before submitting:
///), ensuring consistency with existing project documentation.Summary by CodeRabbit