Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Dec 29, 2022
1 parent 8dfa4a8 commit e4531b8
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Interfaces/SequenceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getStartValue();
* @param T $previousValue
* @return T
*/
//public function getNextValue($previousValue);
public function getNextValue($previousValue);

/**
* @param int|mixed $offset
Expand Down
7 changes: 6 additions & 1 deletion src/Iterators/FloatSequenceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class FloatSequenceIterator implements SequenceIteratorInterface
* @var int
*/
protected int $currentIndex;
/**
* @var float
*/
protected float $currentValue;

/**
* @param FloatSequence $range
Expand All @@ -34,6 +38,7 @@ public function __construct(FloatSequence $range)
{
$this->sequence = $range;
$this->currentIndex = 0;
$this->currentValue = $this->sequence->getStartValue();
}

/**
Expand All @@ -42,6 +47,6 @@ public function __construct(FloatSequence $range)
*/
public function current(): float
{
return $this->sequence[$this->currentIndex];
return $this->currentValue;
}
}
6 changes: 5 additions & 1 deletion src/Iterators/IntSequenceIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class IntSequenceIterator implements SequenceIteratorInterface
* @var int
*/
protected int $currentIndex;
/**
* @var int
*/
protected int $currentValue;

/**
* @param IntSequence $range
Expand All @@ -42,6 +46,6 @@ public function __construct(IntSequence $range)
*/
public function current(): int
{
return $this->sequence[$this->currentIndex];
return $this->currentValue;
}
}
9 changes: 9 additions & 0 deletions src/Structs/FloatExponential.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ public function getStartValue(): float
{
return $this->getValueByIndex(0);
}

/**
* @param float $previousValue
* @return float
*/
public function getNextValue($previousValue): float
{
return $previousValue * $this->step;
}
}
9 changes: 9 additions & 0 deletions src/Structs/FloatSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public function getStartValue(): float
return $this->getValueByIndex(0);
}

/**
* @param float $previousValue
* @return float
*/
public function getNextValue($previousValue): float
{
return $previousValue + $this->step;
}

/**
* {@inheritDoc}
* @return float
Expand Down
9 changes: 9 additions & 0 deletions src/Structs/IntExponential.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ public function getStartValue(): int
{
return $this->getValueByIndex(0);
}

/**
* @param int $previousValue
* @return int
*/
public function getNextValue($previousValue): int
{
return $previousValue * $this->step;
}
}
9 changes: 9 additions & 0 deletions src/Structs/IntRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ public function getStartValue(): int
{
return $this->getValueByIndex(0);
}

/**
* @param int $previousValue
* @return int
*/
public function getNextValue($previousValue): int
{
return $previousValue + $this->step;
}
}
3 changes: 3 additions & 0 deletions src/Traits/SequenceIteratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @implements SequenceIteratorInterface<T>
* @property SequenceInterface<T> $sequence
* @property int $currentIndex
* @property T $currentValue
*/
trait SequenceIteratorTrait
{
Expand All @@ -21,6 +22,7 @@ trait SequenceIteratorTrait
public function next(): void
{
$this->currentIndex++;
$this->currentValue = $this->sequence->getNextValue($this->currentValue);
}

/**
Expand All @@ -46,5 +48,6 @@ public function valid(): bool
public function rewind(): void
{
$this->currentIndex = 0;
$this->currentValue = $this->sequence->getStartValue();
}
}

0 comments on commit e4531b8

Please sign in to comment.