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

Enables iterating over index endpoint results in a given block #57

Merged
merged 1 commit into from
Jan 13, 2022

Conversation

eikes
Copy link
Collaborator

@eikes eikes commented Jan 11, 2022

In stead of creating a very large array I would prefer to iterate over the results directly.

@eikes
Copy link
Collaborator Author

eikes commented Jan 11, 2022

This allows us to do the following:

client = Ioki::PlatformClient.new
client.stations(client.products.first, auto_paginate: true) do |station|
  puts station.id
end

@A5308Y
Copy link
Collaborator

A5308Y commented Jan 13, 2022

LGTM. And sorry for the delay. I'll probably not be working on ioki-ruby this month.

@rmehner
Copy link
Collaborator

rmehner commented Jan 13, 2022

Sorry, didn't have the time earlier. Since we're not streaming, I don't really see the advantage and it loses the clearness of "each" in the call. But that might be just me. I'm not opposed to it, just wondering why this is better than good old ".each do", which signals iteration.

@eikes
Copy link
Collaborator Author

eikes commented Jan 13, 2022

@rmehner The advantage is, that the results array is not created in its entirety, because it could become rather large. Instead each page is requested one by one and the results are yielded. So in a sense, this is a sort of streaming, but rather on a index page basis.

@rmehner
Copy link
Collaborator

rmehner commented Jan 13, 2022

Instead each page is requested one by one and the results are yielded.

I read that part of the code wrong. That makes a lot of sense indeed. Thanks for clarifying!

@rmehner rmehner merged commit 167892c into master Jan 13, 2022
@rmehner rmehner deleted the index-block branch January 13, 2022 10:29
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.

None yet

3 participants