<A>(value: A): Ref<A>Creates a new Ref with the specified initial value (unsafe version).
When to use
Use when you need immediate synchronous construction and can guarantee
that creating the Ref outside of Effect is safe.
Gotchas
Prefer Ref.make for Effect-wrapped creation in Effect programs.
Example (Creating a ref unsafely)
import { Ref } from "effect"
// Create a ref directly without Effect
const counter = Ref.makeUnsafe(0)
// Get the current value
const value = Ref.getUnsafe(counter)
console.log(value) // 0
// Note: This is unsafe and should be used carefully
// Prefer Ref.make for Effect-wrapped creationexport const const makeUnsafe: <A>(value: A) => Ref<A>Creates a new Ref with the specified initial value (unsafe version).
When to use
Use when you need immediate synchronous construction and can guarantee
that creating the Ref outside of Effect is safe.
Gotchas
Prefer Ref.make for Effect-wrapped creation in Effect programs.
Example (Creating a ref unsafely)
import { Ref } from "effect"
// Create a ref directly without Effect
const counter = Ref.makeUnsafe(0)
// Get the current value
const value = Ref.getUnsafe(counter)
console.log(value) // 0
// Note: This is unsafe and should be used carefully
// Prefer Ref.make for Effect-wrapped creation
makeUnsafe = <function (type parameter) A in <A>(value: A): Ref<A>A>(value: Avalue: function (type parameter) A in <A>(value: A): Ref<A>A): interface Ref<in out A>A mutable reference that provides atomic read, write, and update operations.
When to use
Use to keep shared mutable state that is read and updated inside Effect
programs.
Details
A Ref is a thread-safe mutable reference type for shared state. It supports
simple read and write operations as well as atomic transformations.
Example (Reading and updating a ref)
import { Effect, Ref } from "effect"
const program = Effect.gen(function*() {
// Create a ref with initial value
const counter = yield* Ref.make(0)
// Read the current value
const value = yield* Ref.get(counter)
console.log(value) // 0
// Update the value atomically
yield* Ref.update(counter, (n) => n + 1)
// Read the updated value
const newValue = yield* Ref.get(counter)
console.log(newValue) // 1
})
The Ref namespace containing type definitions and utilities.
When to use
Use when referring to type members nested under the Ref namespace.
Ref<function (type parameter) A in <A>(value: A): Ref<A>A> => {
const const self: anyself = 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 RefProto: {
toJSON(this: Ref<any>): {
_id: string
ref: MutableRef.MutableRef<any>
}
pipe(): unknown
toString(): string
[NodeInspectSymbol](): any
"~effect/Ref": { _A: <A>(a: A) => A }
}
RefProto)
const self: anyself.ref = import MutableRefMutableRef.make(value: Avalue)
return const self: anyself
}