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 { flatMap } from 'fp-ts/IO'
import { newIORef } from 'fp-ts/IORef'

assert.strictEqual(flatMap(newIORef(1), (ref) => flatMap(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