Skip to content
New issue

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

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

Already on GitHub? # to your account

Add metered #1294

Merged
merged 3 commits into from
Oct 17, 2018
Merged

Add metered #1294

merged 3 commits into from
Oct 17, 2018

Conversation

vpavkin
Copy link
Contributor

@vpavkin vpavkin commented Oct 17, 2018

No description provided.

/**
* Like [[iterate]], but emits elements with the fixed rate of `d`.
*/
def iterateEvery[F[_], A](d: FiniteDuration)(start: A)(f: A => A)(implicit timer: Timer[F]): Stream[F, A] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the name here. I think this is related to scheduling and perhaps we have somehow express this. Something like iterateAtRate or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pchlupacek I named it consistently with awake family (awakeEvery). But iterateAtRate also fits.
I'm fine with both.

Actually, pronouncing iterateAtRate feels a bit awkward :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not expert on the naming these mouthful operators. Lets see what @SystemFw @mpilquist thinks about this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My whole idea is that awake sort of implies the scheduling, where iterate does not plus, we already use iterate for bunch of scheduling unrelated methods.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iterateEvery is fine as a name, it's consistent with awakeEvery. I'm slightly more doubtful that this op warrants inclusion (you can add an *Every to every op in the lib), but not really opposed to it either, whatever you guys prefer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, as side note we could make perhpas metered to be more effective than zipping, by just inserting it at every value emitted.... like this.evalMap { a => Timer.sleep(d) as a }

Doesn't this change the semantics from fixedRate to fixedDelay?

Copy link
Collaborator

@SystemFw SystemFw Oct 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sense smthing like atMaxRateOf could be more precise

That's not the case, if the other stream is slower it will be slower.

ike this.evalMap { a => Timer.sleep(d) as a }

These semantics are different, that's fixedDelay, not fixedRate

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it does. :-)

Copy link
Contributor Author

@vpavkin vpavkin Oct 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SystemFw

if the other stream is slower it will be slower.

I might be wrong, but I think that's what maxRate implies - if this is too fast, the rate is limited, but if it's slow, the rate is slow as well.

metered is more concise though, I'll go with it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong, but I think that's what maxRate implies

nah, you're right, the ratio there got me :P

@vpavkin
Copy link
Contributor Author

vpavkin commented Oct 17, 2018

I've spent like 15 min on the scala doc, but still feel it can be worded better :)

@vpavkin vpavkin changed the title Add Stream.iterateEvery Add metered Oct 17, 2018
@mpilquist mpilquist merged commit 50e18a9 into typelevel:series/1.0 Oct 17, 2018
@mpilquist mpilquist added this to the 1.0.1 milestone Dec 3, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants