my ($member, $of) = @args{qw(member of)};
die "member bound" if $member->is_bound;
my $set = $state->facts->{$of->bound_value};
- my $stream = DX::ArrayStream->from_array(@{$set}{sort keys %$set});
+ my $stream = $set->to_stream;
return $state->bind_stream_then($member, $stream, $self->next);
}
--- /dev/null
+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}, $value->${\$self->over} => $value }
+ );
+}
+
+1;
use strictures 1;
use Test::More;
use DX::Solver;
+use DX::SetOver;
my @servers = qw(
kitty.scsys.co.uk
);
my $solver = DX::Solver->new(
- facts => { servers => \%servers, shells => \%shells }
+ facts => {
+ servers => DX::SetOver->new(
+ over => sub { $_[0]->{name} }, values => \%servers,
+ ),
+ shells => DX::SetOver->new(
+ over => sub { $_[0]->{name} }, values => \%shells,
+ ),
+ }
);
$solver->add_rule(