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 functions to work on lists #826

Closed
bchamagne opened this issue Jan 12, 2023 · 6 comments
Closed

SC functions to work on lists #826

bchamagne opened this issue Jan 12, 2023 · 6 comments
Assignees
Labels
feature New feature request smart contracts Involve smart contracts

Comments

@bchamagne
Copy link
Member

bchamagne commented Jan 12, 2023

Is your feature request related to a problem?

When writing SC, we need functions to be able to work on lists.

Describe the solution you'd like

We could add a map/filter/reduce. What would be the syntax?

Additional context

No response

@bchamagne bchamagne added feature New feature request smart contracts Involve smart contracts labels Jan 12, 2023
@bchamagne
Copy link
Member Author

@samuelmanzanera
Copy link
Member

I think we can create a new reduce function, which will serve all the purposes

@bchamagne
Copy link
Member Author

I think we can create a new reduce function, which will serve all the purposes

What about the syntax, shoud we include elixir's lambdas in the SC?

reduce(list, 0, fn item, acc -> acc end)

@samuelmanzanera
Copy link
Member

samuelmanzanera commented Jan 13, 2023

I think we can create a new reduce function, which will serve all the purposes

What about the syntax, shoud we include elixir's lambdas in the SC?

reduce(list, 0, fn item, acc -> acc end)

if we don't want to allow lamba functions and to simplify the language, we could leverage macro's style

agg = reduce inputs do
   ...
end
reduce inputs, acc: 0 do
   acc + 1
end

@netboz
Copy link
Contributor

netboz commented Jan 13, 2023

I was browsing some docs a few days ago, looking for equivalent of erlang's filtermap in Elixir, and I remember I read that all Enum api can be reproduced using two of the Enum module provided fonctions. Something like all logic operations can be made from NAND doors.
I will try to find back what are these two fonctions which could be good candidates for a port to smart contracts.

@bchamagne bchamagne self-assigned this Jan 16, 2023
@bchamagne bchamagne changed the title Discussion: SC functions to work on lists SC functions to work on lists Jan 17, 2023
@bchamagne bchamagne mentioned this issue Jan 17, 2023
3 tasks
@samuelmanzanera
Copy link
Member

Another proposition to help the readability as sentence

reduce get_calls(), as: input, with: [my_var_in_acc: 0] do
  
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request smart contracts Involve smart contracts
Projects
Status: Done 🍻
Development

Successfully merging a pull request may close this issue.

3 participants