3 ms·
In functional programming you would store actions in lists with funs/closures inside those data. For example in erlang list of undo actions would look like this
by yetihehe 9y ago
In functional programming you would store actions in lists with funs/closures inside those data. For example in erlang list of undo actions would look like this:
Undo = [ { RemoveJpeg, JpegData} ]
where RemoveJpeg is a fun (like closure) and JpegData is what would be given as argument to this fun. The implementing undo looks like this:
undo_action(Document,[UndoHead|UndoTail]) ->
{UndoFun,UndoData} = UndoHead,
UndoFun(Document,UndoData).
Isn't it simple? RemoveJpeg just returns modified document. undo_action knows only that every action should take two arguments and return modified document.
- pjmlp 9y agoIn Smalltalk: RemoveJpeg <- [:data | ...]. JpegData <- [:data | ...]. Undo <- #( RemoveJpeg, JpegData ). As possible implementation of undo could be undoAction: document with: undoList undoList do: [:aBlock| aBlock value: document].