Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add auto pagination helper methods #702

Merged
merged 26 commits into from
Nov 6, 2023

Conversation

Naoray
Copy link
Collaborator

@Naoray Naoray commented Oct 30, 2023

This is a follow up PR of #701 to add helper methods to the auto pagination functionality. Similar to the advanced usage of the nodejs implementation.

In general this PR allows to chain methods onto the getAutoPaginator() method call in order to manipulate items within the collection. The available methods are

  • all() -> returns the current page items as array
  • get() -> enables to receive a specific item from the collection
  • filter() -> filters through all entries and generates a new collection from the filtered result
  • first() -> returns first item of the collection passing the given truth test
  • map() -> returns the mapped collection for the given callback
  • take() -> returns a new collection with only X items
  • every() -> determines if all items of the collection pass a given truth test
  • count() -> receive the count of the current collection items

This new approach allows for the following usages

$iterator = $client->payments
    ->iterator()
    ->filter(fn (Payment $payment) => $payment->amount->currency === ‘EUR’ && $payment->amount->value > 100)
    ->take(10);

foreach ($iterator as $payment) {
    //…
}

@Naoray Naoray requested a review from sandervanhooft October 30, 2023 11:53
@Naoray Naoray requested a review from sandervanhooft October 30, 2023 15:23
@Naoray Naoray changed the title [WIP] Feature/add auto pagination helper methods Feature/add auto pagination helper methods Nov 2, 2023
@Naoray Naoray merged commit 642f1b8 into master Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants