← Back

Source

IORef

constructor(private value: A) {
    this.read = new IO(() => this.value)
  }

Added in v1.8.0 (data)

Mutable references in the IO monad

Example

import { newIORef } from 'fp-ts/lib/IORef'

assert.strictEqual(
  newIORef(1)
    .chain(ref => ref.write(2).chain(() => ref.read))
    .run(),
  2
)

modify

(f: (a: A) => A): IO<void>

Added in v1.8.0 (method)

write

(a: A): IO<void>

Added in v1.8.0 (method)

newIORef

<A>(a: A): IO<IORef<A>>

Added in v1.8.0 (function)