Skip to content
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

feat(formula): support lambda in function register #4298

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

Dushusir
Copy link
Member

@Dushusir Dushusir commented Dec 13, 2024

What's updated?

Facade API registered formulas support lambda functions

How to test?

  1. Register function use Uniscript
univerAPI.registerFunction({
    calculate: [
        [function (...variants) {
            let sum = 0;

            const last = variants[variants.length - 1];
            if (last.isLambda()) {
                variants.pop();

                const variantsList = variants.map((variant) => Array.isArray(variant) ? variant[0][0]: variant);

                sum += last.executeCustom(...variantsList).getValue();
            }

            for (const variant of variants) {
                sum += Number(variant) || 0;
            }

            return sum;
        }, 'CUSTOMSUM', 'Adds its arguments'],
      // ... more formulas
    ],
});
  1. test =CUSTOMSUM(1,2,LAMBDA(s,c,s+c)), get result 6
  2. A1 input 2, A2 input 3, test =CUSTOMSUM(A1,A2,LAMBDA(s,c,s+c)), get result 10

Pull Request Checklist

  • Related tickets or issues have been linked in the PR description (or missing issue).
  • Naming convention is followed (do please check it especially when you created new plugins, commands and resources).
  • Unit tests have been added for the changes (if applicable).
  • Breaking changes have been documented (or no breaking changes introduced in this PR).

@Dushusir Dushusir requested a review from wzhudev as a code owner December 13, 2024 10:27
Copy link

github-actions bot commented Dec 13, 2024

View Deployment

📑 Examples 📚 Storybook
🔗 Preview link 🔗 Preview link

@Dushusir Dushusir requested review from DR-Univer and wpxp123456 and removed request for DR-Univer December 13, 2024 10:31
Copy link

github-actions bot commented Dec 13, 2024

Playwright test results

passed  21 passed

Details

stats  21 tests across 10 suites
duration  4 minutes, 45 seconds
commit  c2e30b4
info  For more information, see full report

Copy link

codecov bot commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 33.38%. Comparing base (47773f8) to head (c2e30b4).
Report is 7 commits behind head on dev.

Files with missing lines Patch % Lines
...ula/src/engine/value-object/lambda-value-object.ts 0.00% 3 Missing ⚠️
...ngine-formula/src/engine/ast-node/function-node.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #4298      +/-   ##
==========================================
- Coverage   33.46%   33.38%   -0.09%     
==========================================
  Files        2509     2514       +5     
  Lines      129485   129818     +333     
  Branches    28968    29006      +38     
==========================================
+ Hits        43333    43335       +2     
- Misses      86152    86483     +331     

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

@Dushusir Dushusir force-pushed the dushusir/formula-custom1213 branch from fde6140 to c2e30b4 Compare December 18, 2024 13:15
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.

1 participant