package DX::SetOver;

use DX::ArrayStream;
use Moo;

has over => (is => 'ro', required => 1);

has values => (is => 'ro', default => sub { {} });

sub to_stream {
  my ($self) = @_;
  my $values = $self->values;
  return DX::ArrayStream->from_array(@{$values}{sort keys %$values});
}

sub with_value {
  my ($self, $value) = @_;
  return ref($self)->new(%$self, values => { %{$self->values} })
                   ->set_value($value);
}

sub set_value {
  my ($self, $value) = @_;
  $self->values->{$value->${\$self->over}} = $value;
  return $self;
}

1;
