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

Merged
merged 5 commits into from
Jan 10, 2025

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.getFormula().registerFunction('CUSTOMSUM',(...variants) => {
    let sum = 0;

    const last = variants[variants.length - 1];
    if (last.isLambda && 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;
}, 'Adds its arguments');
  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  23 passed

Details

stats  23 tests across 10 suites
duration  5 minutes, 14 seconds
commit  a7f7ab2
info  For more information, see full report

Copy link

codecov bot commented Dec 13, 2024

Codecov Report

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

Project coverage is 32.61%. Comparing base (c504fcb) to head (a7f7ab2).
Report is 15 commits behind head on dev.

Files with missing lines Patch % Lines
...ngine-formula/src/engine/ast-node/function-node.ts 0.00% 3 Missing ⚠️
...ula/src/engine/value-object/lambda-value-object.ts 0.00% 3 Missing ⚠️
...ages/engine-formula/src/functions/base-function.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #4298      +/-   ##
==========================================
- Coverage   32.69%   32.61%   -0.08%     
==========================================
  Files        2567     2575       +8     
  Lines      133268   133699     +431     
  Branches    29659    29740      +81     
==========================================
+ Hits        43568    43602      +34     
- Misses      89700    90097     +397     

☔ 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
Copy link
Member

@wzhudev wzhudev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good to me but we should add an example in the Facade API of regsitering functions.

@Dushusir Dushusir force-pushed the dushusir/formula-custom1213 branch from c2e30b4 to 1e410ac Compare January 7, 2025 06:36
@Dushusir Dushusir requested a review from wzhudev January 7, 2025 07:10
@Dushusir
Copy link
Member Author

Dushusir commented Jan 7, 2025

The implementation looks good to me but we should add an example in the Facade API of regsitering functions.

Added exmaple here https://github.com/dream-num/univer/pull/4298/files#diff-2e2ce04086a2a743f70994698013f64bfe65b0df45577523d7c3eea046ce0202R61

Copy link
Member

@wzhudev wzhudev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

packages/sheets-formula/src/facade/f-formula.ts Outdated Show resolved Hide resolved
Co-authored-by: Wenzhao Hu <wzhudev@gmail.com>
@Dushusir Dushusir merged commit a1b7a16 into dev Jan 10, 2025
9 checks passed
@Dushusir Dushusir deleted the dushusir/formula-custom1213 branch January 10, 2025 03:11
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