Skip to content

Commit

Permalink
Allow all iterables in IterableValue join method (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
bronek89 authored Jan 9, 2019
1 parent c492612 commit 58dd754
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
8 changes: 6 additions & 2 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -3479,7 +3479,7 @@ public function flatMap(callable $transformer);
/**
* @return IterableValue
*/
public function join(IterableValue $other);
public function join(iterable $other);
```

#### Examples
Expand All @@ -3498,7 +3498,7 @@ $range = function (int $start, int $end) {
$one = Wrap::iterable($range(1, 3));
$two = Wrap::iterable($range(8, 10));

var_export($one->join($two)->toArray());
var_export($one->join($two)->join($range(11, 14))->toArray());
```

```
Expand All @@ -3509,6 +3509,10 @@ array (
3 => 8,
4 => 9,
5 => 10,
6 => 11,
7 => 12,
8 => 13,
9 => 14,
)
```

Expand Down
2 changes: 1 addition & 1 deletion examples/example/IterableValue-join.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
$one = Wrap::iterable($range(1, 3));
$two = Wrap::iterable($range(8, 10));

var_export($one->join($two)->toArray());
var_export($one->join($two)->join($range(11, 14))->toArray());
12 changes: 11 additions & 1 deletion spec/InfiniteIterableValueSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,17 @@ function it_can_call_some_action_on_each_item(CallableMock $callable)
$callable->__invoke('item 3')->shouldHaveBeenCalled();
}

function it_joins_with_other_array()
function it_joins_with_other_iterable()
{
$this->beConstructedWith(['a 1', 'a 2', 'a 3']);

$joined = $this->join(['b 1', 'b 2', 'b 3']);

$joined->shouldNotBe($this);
$joined->toArray()->shouldBeLike(['a 1', 'a 2', 'a 3', 'b 1', 'b 2', 'b 3']);
}

function it_joins_with_other_IterableValue()
{
$this->beConstructedWith(['a 1', 'a 2', 'a 3']);

Expand Down
2 changes: 1 addition & 1 deletion src/InfiniteIterableValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function push($value)
/**
* @return IterableValue
*/
public function join(IterableValue $other)
public function join(iterable $other)
{
$clone = clone $this;
$clone->stack = $clone->stack->push(function (iterable $iterable) use ($other) {
Expand Down
2 changes: 1 addition & 1 deletion src/IterableValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function flatMap(callable $transformer);
/**
* @return IterableValue
*/
public function join(IterableValue $other);
public function join(iterable $other);

/**
* @return IterableValue
Expand Down

0 comments on commit 58dd754

Please sign in to comment.