const program = Effect.gen(function* (_) {
const ref = yield* _(
Ref.make({
foo: 0,
})
);
yield* _(
Ref.update(ref, (n) => {
n.foo += 1;
return n;
})
);
// your *supposed* to only update like this
const value = yield* _(Ref.get(ref));
value.foo += 1;
// but nothing stops you from just getting the value and mutating it
yield* _(Console.log(value.foo)); // 2
});
const program = Effect.gen(function* (_) {
const ref = yield* _(
Ref.make({
foo: 0,
})
);
yield* _(
Ref.update(ref, (n) => {
n.foo += 1;
return n;
})
);
// your *supposed* to only update like this
const value = yield* _(Ref.get(ref));
value.foo += 1;
// but nothing stops you from just getting the value and mutating it
yield* _(Console.log(value.foo)); // 2
});