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

SC: add reduce/3 action #839

Closed

Conversation

bchamagne
Copy link
Member

@bchamagne bchamagne commented Jan 17, 2023

Description

Implement a reduce/3 action in the smart contracts.
With the reduce alone we can do all the list manipulation we need.
We could add more convenience functions later such as map/filter.

Syntax:

list = [1,2,3]
sum = reduce(list, 0, fn item, acc ->  
    item + acc
end)

Fixes #826

Current limitation to discuss

  • Impossible to call actions from within the reduce (set_content/add_uco_transfer etc.)
  • Impossible to have a reduce in a reduce
  • Is the elixir lambda syntax good?

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Unit tests added to the suite

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@bchamagne
Copy link
Member Author

Assignations (=) do not work in reduce. I'll fix this ASAP.

@bchamagne
Copy link
Member Author

dot access (x.y) does not work on lambda arguments

        content = reduce(list, [], fn tx, acc ->
            append(acc, tx.address)
        end)

@bchamagne bchamagne marked this pull request as draft January 20, 2023 17:26
@apoorv-2204 apoorv-2204 added the feature New feature request label Jan 24, 2023
@bchamagne bchamagne closed this Feb 3, 2023
@bchamagne
Copy link
Member Author

I will create a new branch and a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SC functions to work on lists
2 participants