I want to write a function similar to this code. I know that this is exact code is not going to work because counter needs to be either state or counter type but that also requires using context blocks. I didnt get that to work either because str.replace() only accepts a function that returns a str Not content.
Is there any solution to get this to work using str.replace()?
#let replace(string) = {
let counter = 0
return string.replace("a", match => {
if calc.even(counter) {
counter += 1
return "a"
} else {
counter += 1
return "b"
}
})
}
#let result = replace("aaa") // Should return "aba"