package DX::Op::MemberOf;

use DX::ArrayStream;
use Moo;

with 'DX::Role::Op';

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

sub run {
  my ($self, $state) = @_;
  ($state, my %args) = $self->_expand_args($state,
    member => $self->member_var,
    of => $self->coll_var
  );
  my ($member, $of) = @args{qw(member of)};
  die "member bound" if $member->is_bound;
  my $set = $state->facts->{$of->bound_value};
  return $state->bind_root_set_then($member->id, $set, $self->next);
}

1;
