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 takeWhile function #22

Merged
merged 2 commits into from
Oct 17, 2023
Merged

Conversation

geminicaprograms
Copy link
Contributor

Takes elements from the source as long as the predicate is satisfied. Note that if the predicate fails then subsequent elements are not longer taken even if they could still satisfy it.
Example:

  Source.empty[Int].takeWhile(_ > 3).toList          // List()
  Source.fromValues(1, 2, 3).takeWhile(_ < 3).toList // List(1, 2)
  Source.fromValues(3, 2, 1).takeWhile(_ < 3).toList // List()

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

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

/** Takes elements from the source as long as predicate `f` is satisfied (returns `true`). Note that once the predicate `f` is not
Copy link
Member

Choose a reason for hiding this comment

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

Same as in the others - I would change the wording a bit to indicate that the returned source is a separate one. E.g. Forwards the elements from this source to the return one, as along ...

Copy link
Contributor

Choose a reason for hiding this comment

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

We're using "sends to the returned channel" in other operators, so let's use a similar wording here for consistency from the user's perspective.

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

Sends elements to the returned channel until predicate is satisfied.
Note that if the predicate fails then subsequent elements are not longer
taken even if they could still satisfy it. Example:

  Source.empty[Int].takeWhile(_ > 3).toList          // List()
  Source.fromValues(1, 2, 3).takeWhile(_ < 3).toList // List(1, 2)
  Source.fromValues(3, 2, 1).takeWhile(_ < 3).toList // List()
@adamw
Copy link
Member

adamw commented Oct 17, 2023

Sorry, needs merge

@geminicaprograms
Copy link
Contributor Author

Sorry, needs merge

Fixed 👍

@geminicaprograms geminicaprograms merged commit fe50670 into master Oct 17, 2023
4 checks passed
@geminicaprograms geminicaprograms deleted the feat_takeWhile branch October 17, 2023 15:20
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