Skip to content

Conversation

@nielsenko
Copy link
Collaborator

@nielsenko nielsenko commented May 22, 2025

Description

This PR introduces a set of functional programming utilities.

  • A new file, 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).
  • These new functional utilities are exported through the main lib/relic.dart file for easier access.

This allows for more expressive handler composition in Relic.

Related Issues

  • Closes: ?

Pre-Launch Checklist

Please ensure that your PR meets the following requirements before submitting:

  • This update focuses on a single feature or bug fix. (For multiple fixes, please submit separate PRs.)
  • I have read and followed the Dart Style Guide and formatted the code using dart format.
  • I have referenced at least one issue this PR fixes or is related to.
  • I have updated/added relevant documentation (doc comments with ///), ensuring consistency with existing project documentation.
  • I have added new tests to verify the changes.
  • All existing and new tests pass successfully.
  • I have documented any breaking changes below.

Summary by CodeRabbit

  • New Features
    • Introduced functional programming utilities, including extensions for function piping, composition, partial application, and tuple-based invocation, supporting up to four parameters.
  • Tests
    • Added comprehensive tests to ensure the correctness of the new functional programming utilities.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 22, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

A 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

File(s) Change Summary
lib/relic.dart Added export for src/util/functional.dart to the library's public API.
lib/src/util/functional.dart New file: Implements extensions for pipe, compose, apply (partial application), and pack (tuple argument) for functions up to arity four.
test/util/functional_test.dart New file: Adds unit tests for all functional extensions, covering various data types and arities.

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
Loading
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
Loading
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch functional

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented May 22, 2025

Codecov Report

❌ Patch coverage is 95.83333% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.44%. Comparing base (3ab7119) to head (92957de).

Files with missing lines Patch % Lines
lib/src/message/response.dart 75.00% 6 Missing ⚠️
lib/src/adapter/io/io_relic_web_socket.dart 77.77% 2 Missing ⚠️
lib/src/io/static/static_handler.dart 95.74% 2 Missing ⚠️
lib/src/middleware/middleware_logger.dart 84.61% 2 Missing ⚠️
lib/src/relic_server.dart 90.47% 2 Missing ⚠️
...c/headers/typed/headers/authentication_header.dart 91.66% 1 Missing ⚠️
...rc/headers/typed/headers/authorization_header.dart 93.75% 1 Missing ⚠️
...ib/src/headers/typed/headers/forwarded_header.dart 95.45% 1 Missing ⚠️
...eaders/typed/headers/permission_policy_header.dart 94.73% 1 Missing ⚠️
lib/src/io/static/cache_busting_config.dart 80.00% 1 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #77      +/-   ##
==========================================
+ Coverage   91.33%   91.44%   +0.10%     
==========================================
  Files          89       90       +1     
  Lines        3428     3472      +44     
  Branches     1763     1777      +14     
==========================================
+ Hits         3131     3175      +44     
  Misses        297      297              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nielsenko nielsenko self-assigned this May 22, 2025
@nielsenko nielsenko force-pushed the functional branch 2 times, most recently from 28c155c to c7f046c Compare May 26, 2025 06:33
@nielsenko
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7bb4631 and e77cd8a.

📒 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.

@nielsenko
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nielsenko nielsenko requested a review from SandPod June 9, 2025 13:22
@nielsenko nielsenko marked this pull request as ready for review June 9, 2025 13:23
@nielsenko nielsenko marked this pull request as draft June 12, 2025 05:00
@SandPod SandPod force-pushed the main branch 2 times, most recently from bf48ea0 to e362193 Compare August 28, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants