<T>(value: T): MutableRef<T>Creates a new MutableRef with the specified initial value.
When to use
Use to create a synchronous MutableRef initialized with a value.
Example (Creating mutable refs)
import { MutableRef } from "effect"
// Create a counter reference
const counter = MutableRef.make(0)
console.log(MutableRef.get(counter)) // 0
// Create a configuration reference
const config = MutableRef.make({ debug: false, timeout: 5000 })
console.log(MutableRef.get(config)) // { debug: false, timeout: 5000 }
// Create a string reference
const status = MutableRef.make("idle")
MutableRef.set(status, "running")
console.log(MutableRef.get(status)) // "running"export const const make: <T>(value: T) => MutableRef<T>Creates a new MutableRef with the specified initial value.
When to use
Use to create a synchronous MutableRef initialized with a value.
Example (Creating mutable refs)
import { MutableRef } from "effect"
// Create a counter reference
const counter = MutableRef.make(0)
console.log(MutableRef.get(counter)) // 0
// Create a configuration reference
const config = MutableRef.make({ debug: false, timeout: 5000 })
console.log(MutableRef.get(config)) // { debug: false, timeout: 5000 }
// Create a string reference
const status = MutableRef.make("idle")
MutableRef.set(status, "running")
console.log(MutableRef.get(status)) // "running"
make = <function (type parameter) T in <T>(value: T): MutableRef<T>T>(value: Tvalue: function (type parameter) T in <T>(value: T): MutableRef<T>T): interface MutableRef<out T>A synchronous mutable reference that stores a current value.
When to use
Use to keep local mutable state in a stable, pipeable reference.
Details
Read or write the value directly through .current, or use the MutableRef
helpers for pipeable updates such as get, set, update, and
compareAndSet. All operations mutate the same reference in place.
Example (Creating and updating refs)
import { MutableRef } from "effect"
// Create a mutable reference
const ref: MutableRef.MutableRef<number> = MutableRef.make(42)
// Read the current value
console.log(ref.current) // 42
console.log(MutableRef.get(ref)) // 42
// Update the value
ref.current = 100
console.log(MutableRef.get(ref)) // 100
// Use with complex types
interface Config {
timeout: number
retries: number
}
const config: MutableRef.MutableRef<Config> = MutableRef.make({
timeout: 5000,
retries: 3
})
// Update through the interface
config.current = { timeout: 10000, retries: 5 }
console.log(config.current.timeout) // 10000
MutableRef<function (type parameter) T in <T>(value: T): MutableRef<T>T> => {
const const ref: anyref = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.create(o: object | null): any (+1 overload)Creates an object that has the specified prototype or that has null prototype.
create(const MutableRefProto: Omit<
MutableRef<unknown>,
"current"
>
MutableRefProto)
const ref: anyref.current = value: Tvalue
return const ref: anyref
}