bowbahdoe / elm-history / History

This library gives you a way to manage a series of values where you are only interested in one value at a time and are interested in potentially revisiting previous values.

The provided data structure is referred to here as a "History", although it is more often referred to as a "Zip List". This is meant to provide you with a better idea of what you can effectively use this library for. Namely, you can use this data structure to power any feature that fits the pattern of "undo" and "redo".

For more insights on why you might want to use this data structure, I highly reccomend watching this talk

If you are here looking for a way to manage the actual history of a web browser, you should instead be looking at the elm/Browser package.

The Data Structure


type History a

A "History" of values.

Create

new : a -> History a

Creates a new History, starting with the given value.

fromList : List a -> Maybe (History a)

Creates a history from a list. Treats the first element in the list as the present state and all the other items as the states that occurred in the past. If the list is empty, then no History will be produced.

Maneuvering

forward : History a -> History a

Moves forward in the history. If there are no values in the future then there is no change. This is synonymous with a "redo" operation.

back : History a -> History a

Moves backward in the history. If there are no past values then there is no change. This is synonymous with an "undo" operation.

current : History a -> a

Gets the current value in the History.

to : a -> History a -> History a

Moves the History to a new value. This will erase anything in the future. Think of it like time travel: If you go back in time and change what happens next, all your knowledge of the future is now irrelevant.

evolve : (a -> a) -> History a -> History a

Moves the History to a new value obtained by applying a function to the current value. Just like to, this will erase any of your knowledge of the future.

Transform

map : (a -> b) -> History a -> History b

Maps a function over all the values in the history.