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

feat: implement drop function #20

Merged
merged 1 commit into from
Oct 17, 2023
Merged

feat: implement drop function #20

merged 1 commit into from
Oct 17, 2023

Conversation

geminicaprograms
Copy link
Contributor

Drop n elements from the source and emit subsequent elements (if any left) e.g.:

  Source.empty[Int].drop(1).toList          // List()
  Source.fromValues(1, 2, 3).drop(1).toList // List(2 ,3)
  Source.fromValues(1).drop(2).toList       // List()

class SourceOpsDropTest extends AnyFlatSpec with Matchers {
behavior of "Source.drop"

it should "not drop from the empty source" in scoped {
Copy link
Member

Choose a reason for hiding this comment

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

let's use supervised where possible; it should be our "default" scoping tool, unless some specific requirements necessitate usage of scoped

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -141,6 +141,24 @@ trait SourceOps[+T] { this: Source[T] =>

def take(n: Int)(using Ox, StageCapacity): Source[T] = transform(_.take(n))

/** Drops `n` elements from the source and emits any subsequent elements.
Copy link
Member

Choose a reason for hiding this comment

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

I'd change the wording slightly to indicate that we return a different source than the current one. E.g.:

Drops `n` elements from this source and forwards any subsequent ones to the returned channel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

import ox.*

class SourceOpsDropTest extends AnyFlatSpec with Matchers {
behavior of "Source.drop"
Copy link
Contributor

Choose a reason for hiding this comment

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

thought: How about an additional test case to verify that drop(0) doesn't drop anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Drop `n` elements from the source and emit subsequent elements (if any
left) e.g.:

  Source.empty[Int].drop(1).toList          // List()
  Source.fromValues(1, 2, 3).drop(1).toList // List(2 ,3)
  Source.fromValues(1).drop(2).toList       // List()
@adamw adamw merged commit c7a9686 into master Oct 17, 2023
4 checks passed
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.

3 participants