Play with Ref

Ref represents an immutable reference to a mutable value

Ref

// describe a reference to A
export interface Ref<A> {
  // read the current value
  readonly get: T.Effect<T.NoEnv, never, A>;
  
  // set the value
  set(a: A): T.Effect<T.NoEnv, never, A>;
  
  // update the value
  update(f: FunctionN<[A], A>): T.Effect<T.NoEnv, never, A>;
  
  // update the value and return B
  modify<B>(f: FunctionN<[A], readonly [B, A]>): T.Effect<T.NoEnv, never, B>;
}

// create a new reference
export const makeRef = <A>(initial: A): T.Effect<T.NoEnv, never, Ref<A>>

Usage

Last updated

Was this helpful?