Skip to content

Commit

Permalink
Removing "limit" from search. This should be composed elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed May 2, 2015
1 parent 1fa74e3 commit 149203b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
11 changes: 2 additions & 9 deletions src/ResultPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,17 @@ public function each(callable $handleResult)
* Returns an iterator that iterates over the values of applying a JMESPath
* search to each result yielded by the iterator as a flat sequence.
*
* @param string $expression JMESPath expression to apply to each result.
* @param int|null $limit Total number of items that should be returned
* or null for no limit.
* @param string $expression JMESPath expression to apply to each result.
*
* @return \Iterator
*/
public function search($expression, $limit = null)
public function search($expression)
{
// Apply JMESPath expression on each result, but as a flat sequence.
$xf = t\mapcat(function (Result $result) use ($expression) {
return (array) $result->search($expression);
});

// Apply a limit to the total items returned.
if ($limit) {
$xf = t\comp($xf, t\take($limit));
}

// Return items as an iterator.
return t\to_iter($this, $xf);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/ResultPaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function testCanSearchOverResultsUsingFlatMap()
$this->addMockResults($client, [
new Result(['LastToken' => 'b2', 'TableNames' => ['a1', 'b2']]),
new Result(['LastToken' => 'b2', 'TableNames' => []]),
new Result(['TableNames' => ['c3']]),
new Result(['LastToken' => 'b2', 'TableNames' => ['c3']]),
new Result(['TableNames' => ['d4']]),
], function () use (&$requestCount) {
$requestCount++;
Expand All @@ -170,12 +170,12 @@ public function testCanSearchOverResultsUsingFlatMap()
]);

$tableNames = [];
foreach ($paginator->search('TableNames[][::-1]', 3) as $table) {
foreach ($paginator->search('TableNames[][::-1]') as $table) {
$tableNames[] = $table;
}

$this->assertEquals(3, $requestCount);
$this->assertEquals(['1a', '2b', '3c'], $tableNames);
$this->assertEquals(4, $requestCount);
$this->assertEquals(['1a', '2b', '3c', '4d'], $tableNames);
}

public function testGracefullyHandlesSingleValueResults()
Expand Down

0 comments on commit 149203b

Please sign in to comment.