package at.petrak.hexcasting.common.casting.operators.lists

import at.petrak.hexcasting.api.casting.*
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota

object OpModifyInPlace : ConstMediaAction {
    override val argc = 3
    override fun execute(args: List<Iota>, ctx: CastingEnvironment): List<Iota> {
        val list = args.getList(0, argc)
        val index = args.getPositiveIntUnder(1, list.size(), argc)
        val iota = args[2]
        return list.modifyAt(index) { SpellList.LPair(iota, it.cdr) }.asActionResult
    }
}
