// Alternative to built-in brw<a>, represents state. // Suitable for cases where you…
- User
// Alternative to built-in
brw<a>, represents state. // Suitable for cases where you want to abstract a piece of code that // uses non-null pointers. aspect ref = * set(this: ref, value: a): ref * get(this: ref): a;// Abstracted version of
ref<a>, represents non-standard state. // Suitable for cases where you might want nullability or similar // variations of state. aspect res<r, a> = * set(this: res<r, a>, value: a): res<r, a> * get(this: res<r, a>): r; - Assistant
// Example usage:
// Using
ref<a>let myRef: ref = { value: 0, set(newValue: number): ref { this.value = newValue; return this; }, get(): number { return this.value; } };myRef.set(10); // sets the value to 10 console.log(myRef.get()); // prints 10
// Using
res<r, a>let myRes: res<number | null, number> = { value: 0, set(newValue: number): res<number | null, number> { this.value = newValue; return this; }, get(): number | null { return this.value; } };myRes.set(10); // sets the value to 10 console.log(myRes.get()); // prints 10
myRes.set(null); // sets the value to null console.log(myRes.get()); // prints null