# before
sub append {
  my $itit = shift;
  my ($cur_it, $val);
  $cur_it = $itit->();
  return Iterator {
    return unless defined $cur_it;
    until (defined($val = $cur_it->())) {
      return if not defined($cur_it = $itit->());
      if (not_an_iterator($cur_it)) {
        my $val = $cur_it;
        $cur_it = $itit->();
        return $val;
      }
    }
    return $val;
  }
}

# after
sub append {
  my @stack = @_;
  return Iterator {
    while (@stack) {
      my $val = $stack[0]->();
      if (@stack < 2 and $val is iterator) {
        unshift @stack, $val;
      } elsif (not defined $val) {
        shift @stack;
      } else {
        return $val
      }
    }
    return undef;
  }
}

