State

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.

struct State (
Type
int Size = 16
) {
FixedSizeArray!(ImmuWrapper!Type, Size) state;
FixedSizeArray!(StringParameter, Size - 1) parameters;
}

Disabled Default Constructor

A disabled default is present on this object. To use it, use one of the other constructors or a factory function.

Constructors

this
this(Type initState)

Construct the State object with an initState.

Members

Functions

exe
void exe(F f, Args args)

Execute the function F on the current value with parameters Args....

peek
immutable(Type) peek()

Peek at the current element.

toString
string toString()
void toString(D app)

Call this to get an output of the last few states and the passed parameter.

Examples

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());

Meta