I love the @value decorator that generates __init__
methods for structs. Is there a pattern to support computed fields that are not initialized through input arguments?
For example in the struct below I would like to pass length
, bitmap
and buffers
in the constructor but have _null_count
default to -1. Then the _null_count will be initialized on the first call to the null_count()
method.
@value
struct ArrayData(Movable, Writable):
var length: Int
var bitmap: ArcPointer[Bitmap]
var buffers: List[ArcPointer[Buffer]]
var _null_count: Int
In Python, with dataclasses, you could initialize _null_count
to -1
during the field declaration.
I can of course write my own __init__
and friends, wondering if there is a way for me to be lazy.
Thanks!
Marius