<A>(value: A): Effect.Effect<Ref<A>>Creates a new Ref with the specified initial value.
When to use
Use to create a Ref for shared mutable state inside an Effect program.
Example (Creating a ref)
import { Effect, Ref } from "effect"
const program = Effect.gen(function*() {
const ref = yield* Ref.make(42)
const value = yield* Ref.get(ref)
console.log(value) // 42
})export const const make: <A>(
value: A
) => Effect.Effect<Ref<A>>
Creates a new Ref with the specified initial value.
When to use
Use to create a Ref for shared mutable state inside an Effect program.
Example (Creating a ref)
import { Effect, Ref } from "effect"
const program = Effect.gen(function*() {
const ref = yield* Ref.make(42)
const value = yield* Ref.get(ref)
console.log(value) // 42
})
make = <function (type parameter) A in <A>(value: A): Effect.Effect<Ref<A>>A>(value: Avalue: function (type parameter) A in <A>(value: A): Effect.Effect<Ref<A>>A): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<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): Effect.Effect<Ref<A>>A>> => import EffectEffect.sync(() => 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(value: Avalue))