Closed GuillemGongora closed 3 years ago
Good idea. Although I now also think that a replace()
function would be nice that allows you to replace all values with another value. Like:
ring vals1 [1 2 3 4 5]
ring vals2 every(abc 2 8)
//=> [1 2 3 4 5 0 0 0 0 0 0 0 0 0 0 0]
// replace all 0's with 1's
ring vals3 replace(vals2 0 1)
//=> [1 2 3 4 5 1 1 1 1 1 1 1 1 1 1 1]
Both could be useful, because replace might change your original ring:
ring vals1 [1 2 0 4 5]
ring vals2 every(vals1 2 8)
//=> [1 2 0 4 5 0 0 0 0 0 0 0 0 0 0 0]
// replace all 0's with 1's
ring vals3 replace(vals2 0 1)
//=> [1 2 1 4 5 1 1 1 1 1 1 1 1 1 1 1]
Ah yes, did not think about that yet!
Is now included in the latest version as 3rd argument:
ring melody [5 7 3 9 1]
ring phrase every(melody 2 7 12)
print phrase
// => [5 7 3 9 1 12 12 12 12 12 12 12 12 12]
An additional argument could be added to
every()
to set the value of the end padding. For instance:ring abc(1 2 3 4 5) -> (1 2 3 4 5)
ring test every(abc 2 8 1) -> (1 2 3 4 5 1 1 1 1 1 1 1 1 1 1 1)