Hyperlinkv0.8.0-beta.28

MutableRef

MutableRef.makeconsteffect/MutableRef.ts:113
<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"
constructors
export const make = <T>(value: T): MutableRef<T> => {
  const ref = Object.create(MutableRefProto)
  ref.current = value
  return ref
}
Referenced by 2 symbols