Class History<T>

Class representing a history of values. History

Example: Create a new History instance with an initial value of 10.

const history = History.create(10)

Example: Create a new History instance using the alias method.

const historyOfValue = History.of(50)

Example: Add new values using the map method.

const updatedHistory = history
.map(value => value + 5)
.map(value => value * 2)

Example: Get the current value from the updated history.

const currentValue = updatedHistory.current() // output: 30

Example: Reset the history to its initial value.

const resetHistory = updatedHistory.reset()

Example: Rollback to a previous value.

const rolledBackHistory = resetHistory.rollback()

Type Parameters

  • T

    The type of values in the history.

Constructors

Properties

Methods

Constructors

  • Private

    Private constructor to create an instance of History.

    Type Parameters

    • T

    Parameters

    • history: T[]

      The history of values.

    Returns History<T>

Properties

history: T[]

The history of values.

Methods

  • Get the current value at the end of the history.

    Returns T

    The current value.

  • Apply a function to the current value and add the new value to the history.

    Parameters

    • fn: ((value) => T)

      The function to be applied to the current value.

        • (value): T
        • Parameters

          • value: T

          Returns T

    Returns History<T>

    A new instance of History with the updated value.

  • Revert the history to a previous value, removing the indicated number of values.

    Parameters

    • steps: number = 1

      The number of values to revert. Default is 1.

    Returns History<T>

    A new instance of History with the history reverted.

  • Create a new instance of History with an initial value.

    Type Parameters

    • T

    Parameters

    • initial: T

      The initial value.

    Returns History<T>

    A new instance of History.

  • Create a new instance of History with an initial value.

    Type Parameters

    • T

    Parameters

    • value: T

      The initial value.

    Returns History<T>

    A new instance of History.

    Alias

    History#create

Generated using TypeDoc