Reputation: 41
I'd like to loop over an array of values. Something like
for each foo in bar[] do
{
foo.doSomething
}
How do I do this in pact?
I see in your todomvc example that you get a value back from the blockchain and use map within the react framework to effectively iteratate through this
https://github.com/kadena-io/pact-todomvc/blob/master/src/components/todo-app.jsx#L94
But can you do this within the pact language itself? Something akin to a cursor function in Oracle PL/SQL
Upvotes: 2
Views: 185
Reputation: 41
So here's an example of this now in use. In this case, add one to each number in the list
pact> (map (+ 1) [1 2 3])
[2 3 4]
Upvotes: 1
Reputation: 111
Pact has a built-in function map
that lets you iterate through a list.
See here for the detailed description: https://pact-language.readthedocs.io/en/latest/pact-functions.html#map
(map (do-something) bar)
would do what you described.
Upvotes: 3