Undo in D

bauss jj_1337 at live.dk
Sat Jun 23 18:06:27 UTC 2018


On Saturday, 23 June 2018 at 01:58:31 UTC, DigitalDesigns wrote:
> Is there any idiomatic undo designs in D that give a more 
> natural implementation than the standard techniques?

There is the solution above, but there I've implemented something 
similar in Diamond.

It's a little bit different concept since it's based on 
"snapshot" types which basically is a type that keeps snapshots 
of its values and thus you can change the state of it.

They're used for transactions within Diamond, which could 
show-case how to use them.

http://diamondmvc.org/docs/data/#transactions

But a quick example would be from the docs:

```
import diamond.data;

auto value = new Snapshot!int;

value = 100;
value = 200;
value = 300;
value = 400;

import std.stdio : writefln;
writefln("%d %d %d %d %d", value[0], value[1], value[2], 
value[3], value);

// Prints: 100 200 300 400 400
```

For more information also see:

http://diamond.dpldocs.info/diamond.data.snapshot.Snapshot.html


More information about the Digitalmars-d-learn mailing list