import std.typecons : Nullable;
void mapFoo(Foo foo, uint[] sequence)
if (sequence.length == 0)
assert(this.foo.isNull, "trying to redefine input");
auto value = sequence.popFrontValue;
auto node = this.getOrCreateChildNodeForValue(value);
node.mapFoo(foo, sequence);
private Node getOrCreateChildNodeForValue(uint value)
if ((value in this.children) is null)
this.children[value] = node;
node = this.children[value];
private uint popFrontValue(ref uint[] array) pure
import std.range.primitives : popFront;
root.mapFoo(Foo(1), [1]);
root.mapFoo(Foo(2), [2, 3, 4]);
root.mapFoo(Foo(3), [2, 3, 5]);
assert(1 == root.children[1].foo.get.value);
assert(2 == root.children[2].children[3].children[4].foo.get.value);
assert(3 == root.children[2].children[3].children[5].foo.get.value);