Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?hh //strict
  2.  
  3. final class Arugments
  4. {
  5.  
  6. private int $position = 0;
  7. private Vector<string> $args;
  8.  
  9. public function __construct(
  10. Traversable<string> $args = []
  11. )
  12. {
  13. $this->args = Vector::fromItems($args);
  14. }
  15.  
  16. public function current(): string {
  17. return $this->args->at($this->position);
  18. }
  19.  
  20. public function valid(): bool {
  21. return $this->args->count() > $this->position;
  22. }
  23.  
  24. public function next(): string {
  25. return $this->args->at($this->position + 1);
  26. }
  27.  
  28. public function has(int $number): int {
  29. $willConsumedAt = $this->position + $number;
  30. return $this->args->count() >= $willConsumedAt;
  31. }
  32.  
  33. public function take(int $value): Vector<string> {
  34. return $this->args->slice($this->position, $value);
  35. }
  36.  
  37. public function consume(int $value = 1) {
  38. $this->position += $value;
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement