package DX::Op::FindAll;

use DX::Op::FromCode;
use DX::Op::FindAllCollect;
use DX::Var;
use DX::OrderedSet;
use DX::Op::Return;
use Moo;

with 'DX::Role::Op::FindIsh';

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

sub make_result_handler {
  my ($self, $coll) = @_;
  my $coll_name = $self->coll_name;
  DX::Op::FromCode->new(
    code => sub {
      my ($self, $state) = @_;
      $state->bind_value($state->scope->{$coll_name} => $coll)
            ->then($self->next);
    },
    next => $self->next
  );
}

1;
