Skip to content

Commit

Permalink
Introducing Any.skip(n?)
Browse files Browse the repository at this point in the history
Exposes the functionality of Iterator.skip-one/skip-at-least.  This
allows you to do something like:

  for "file".IO.lines.skip(10).head(10) {
  }

to get the second 10 lines of a file.  I've waited to push this until
after the 2017.01 release, so that we have about a month to revert it
should it be considered an addition we could do without  :-)
  • Loading branch information
lizmat committed Jan 21, 2017
1 parent a5ffe4d commit 8a6bfc6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/Any-iterable-methods.pm
Expand Up @@ -1933,6 +1933,10 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
multi method rotor(Any:D: *@cycle, :$partial) {
Seq.new(Rakudo::Iterator.Rotor(self.iterator,@cycle,$partial))
}

proto method skip(|) { * }
multi method skip() { Seq.new(self.iterator).skip }
multi method skip(Int() $n) { Seq.new(self.iterator).skip($n) }
}

BEGIN Attribute.^compose;
Expand Down
3 changes: 3 additions & 0 deletions src/core/Seq.pm
Expand Up @@ -368,6 +368,9 @@ my class Seq is Cool does Iterable does PositionalBindFailover {
multi method from-loop(&body, &cond, &afterwards) {
Seq.new(CStyleLoopIter.new(&body, &cond, &afterwards))
}

multi method skip() { nqp::stmts( $!iter.skip-one, self) }
multi method skip(Int() $n) { nqp::stmts( $!iter.skip-at-least($n), self) }
}

sub GATHER(&block) {
Expand Down

0 comments on commit 8a6bfc6

Please sign in to comment.