How to implement this in nim
import sequtils
import sugar
var list = @[1,2,3]
var found = list.filterIt ( it==2 )
var foundPtr = addr found[0]
foundPtr.* = 3
echo list # expected: [1,3,3]
var list = @[1,2,3]
for n in list.mitems:
if n == 2:
n = 3
echo list == @[1,3,3]
[] method already returns var T. By default, you cant pass it to vars, but can to procedures.
proc myInc(mut: var int) = mut += 1
var test = @[1, 2, 3]
test[1].myInc
If you want to save ref to variable you can use "views"
{.experimental: "views".}
var test = @[1, 2, 3]
let myRef: var int = test[1]
inc myRed
echo test
For your case you also can use applyIt from sequtils
var test = @[1, 2, 3]
test.applyIt(if it == 2: it + 1 else: it)
echo test