package DX::Step::Backtrack;

use DX::Class;

with 'DX::Role::Step';

sub apply_to {
  my ($self, $ss) = @_;
  my ($first_alt, @rest_alt) = @{$ss->alternatives};
  return $ss->but(next_step => $ss->on_exhaustion_step) unless $first_alt;
  return $ss->but(
    current_hypothesis => $first_alt->[0],
    alternatives => \@rest_alt,
    next_step => $first_alt->[1],
    is_solution_state => 0,
  );
}

1;
