|(require struct-set)||package: struct-set|
This module defines helpers for immutably updating structs. Notably, updating a struct using this package doesn’t change its type like struct-copy does. Under the hood, it derives a generic method for copying structs that is then dispatched to for updating.
(struct/set id maybe-super (field ...) struct-option ...)
> (struct/set fruit (price)) > (struct/set apple fruit (oxidized?)) > (struct/set banana fruit (too-ripe?))
(struct-set id struct-expr [fld-id expr] ...)
> (define old-apple (apple 1.5 #t)) > (define new-apple (struct-set fruit old-apple [price 1.0])) > (fruit-price new-apple)
> (apple-oxidized? new-apple)
(struct-update id struct-expr [fld-id update-expr] ...)