A disabled default is present on this object. To use it, use one of the other constructors or a factory function.
Construct the State object with an initState.
Execute the function F on the current value with parameters Args....
Peek at the current element.
Call this to get an output of the last few states and the passed parameter.
Ditto
1 struct Foo { 2 int value; 3 } 4 5 struct FooRedux { 6 Foo fun(const(Foo) foo) { 7 return Foo(foo.value + 2); 8 } 9 } 10 11 Foo bar(const(Foo) foo, int i) { 12 return Foo(foo.value + i); 13 } 14 import std.stdio; 15 import exceptionhandling; 16 17 const begin = 1337; 18 19 auto fooState = State!(Foo)(Foo(begin)); 20 21 int cnt = 0; 22 for(int i = 1; i <= 126; ++i) { 23 fooState.exe(&bar, i); 24 cnt += i; 25 cast(void)assertEqual(fooState.peek().value, begin + cnt); 26 } 27 28 cast(void)assertEqual(fooState.peek().value, begin + cnt); 29 30 auto f = fooState.peek(); 31 32 FooRedux fr; 33 fooState.exe(&fr.fun); 34 writeln(fooState.toString());
State can be your single source of truth if you let it. Call exe to run a function and use to peek to have a look at the last version of immutable(Type). You should not hold a copy of the data returned by peek.