Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Writer<S, A>

The Writer monad provides the ability to accumulate a secondary Story (S) value in addition to the return value (A) of a computation.

Type parameters

  • S

    The array-based value of the Story (the accumulator).

  • A

    The current return value of the computation.

Hierarchy

  • Writer

Implements

Index

Properties

empty

empty: A & object = empty<A>()

Methods

apply

  • Applies a function stored as the value of another Writer to the value of this Writer.

    Type parameters

    • B

    Parameters

    Returns Writer<S, B>

censor

  • censor(func: function): Writer<S, A>
  • Modify the Writer's story by applying a function.

    Parameters

    • func: function
        • (s: S[]): S[]
        • Parameters

          • s: S[]

          Returns S[]

    Returns Writer<S, A>

equals

  • equals(other: Writer<S, A>): boolean
  • Checks equality between two Writers of the same type.

    Parameters

    Returns boolean

eval

  • eval(): A
  • Returns the value at the end of a sequence of Writer computations.

    Returns A

exec

  • exec(): S[]
  • Returns the story at the end of a sequence of Writer computations.

    Returns S[]

fmap

  • fmap<B>(func: function): Writer<S, B>
  • Binds a new operation to this Writer.

    Type parameters

    • B

    Parameters

    • func: function

    Returns Writer<S, B>

isEmpty

  • isEmpty(): boolean

listen

  • listen<B>(func: function): Writer<S, B>
  • Modifies the Writer to include changes to the value.

    Type parameters

    • B

    Parameters

    • func: function

    Returns Writer<S, B>

map

  • map<B>(func: function): Writer<S, B>
  • Applies a function to the accumulated value of a Writer.

    Type parameters

    • B

    Parameters

    • func: function
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    Returns Writer<S, B>

on

  • on(callback: function): Writer<S, A>
  • Run a side effect on the value.

    Parameters

    • callback: function
        • (a: A): void
        • Parameters

          • a: A

          Returns void

    Returns Writer<S, A>

Static tell

  • tell<S, A>(story: S[]): Writer<S, A & object>
  • Creates a new Writer with an initial story and an empty value.

    Type parameters

    • S

    • A

    Parameters

    • story: S[]

    Returns Writer<S, A & object>

Static unit

  • unit<S, A>(a: A): Writer<S, A>
  • Creates a new Writer with an empty story and an initial value.

    Type parameters

    • S

    • A

    Parameters

    • a: A

    Returns Writer<S, A>

Static writer

  • writer<S, A>(story: S[], value: A): Writer<S, A>
  • Creates a new Writer with a story and a value.

    Type parameters

    • S

    • A

    Parameters

    • story: S[]
    • value: A

    Returns Writer<S, A>

Generated using TypeDoc