Open njordhov opened 2 years ago
As an alternative, the map function could accept non-iterable parameters and pass them to each iteration.
(define-read-only (inc-many (items (list 20 uint)))
(map + items u1)
)
In this example, each time +
is called, u1
is passed as the second parameter.
This change should also be applied to fold
and filter
.
A
repeat
function can generate a list of identical items repeated a given number of times.Lists of explicitly repeated items are used in many Clarity contracts, typically with
map
andfold
. For illustration, here is a function to increment integers in a list with an integer incremental `n':Using
repeat
simplifies this to:The cost of using
repeat
should be the same or less than having explicitly repeated items in the contract.