import {SliceAccessors, SliceOptions, Sliceable} from "./types.js" export class Slice implements Sliceable { #options: SliceOptions constructor(options: SliceOptions) { this.#options = options } get state() { return this.#options.getter( this.#options.parent.state ) } transmute(fun: (x: X) => X) { this.#options.parent.transmute(state => { const x1 = this.#options.getter(state) const x2 = fun(x1) const new_state = this.#options.setter(state, x2) return new_state }) } slice({getter, setter}: SliceAccessors) { return new Slice({ parent: this as Sliceable, getter, setter, }) } }