NAME

Quantum::Superpositions::Lazy::State - a weighted state implementation

DESCRIPTION

This is a simple implementation of a state that contains a weight and a value. The states are meant to be immutable, so once created you cannot change the value or weight of a state (without cloning it).

METHODS

new

        my $state = Quantum::Superpositions::Lazy::State->new(
                weight => 2,
                value => "on"
        );

A generic Moose constructor. Accepts two arguments: weight of numeric type (positive), which is optional and 1 by default, and value of any type (defined), which is required.

weight

Returns the weight.

value

Returns the value.

reset

Resets the state of a superposition inside of the value attribute, if that value is indeed a superposition.

clone

Creates a new state with the parameters of the current one.

clone_with

        # doubles the weight on the cloned state
        $state->clone_with(weight => sub { shift() * 2 });

Clones the objects with clone and then applies some transformators on top of the object fields.

merge

Merges two states into one. Only possible for values that are the same (compared as strings with eq). The weights are added together on the resulting state.

SEE ALSO

Quantum::Superpositions::Lazy::ComputedState