Skip to main content Link Search Menu Expand Document (external link)

IORef overview

Mutable references in the IO monad

Added in v2.0.0


Table of contents


constructors

newIORef

Signature

export declare function newIORef<A>(a: A): IO<IORef<A>>

Added in v2.0.0

model

IORef (class)

Signature

export declare class IORef<A> {
  constructor(private value: A)
}

Example

import { io } from 'fp-ts/IO'
import { newIORef } from 'fp-ts/IORef'

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

Added in v2.0.0

write (method)

Signature

write(a: A): IO<void>

Added in v2.0.0

modify (method)

Signature

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

Added in v2.0.0

read (property)

Signature

readonly read: IO<A>

Added in v2.0.0