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 head and headOption operators #25

Merged
merged 1 commit into from
Oct 26, 2023

Conversation

geminicaprograms
Copy link
Contributor

@geminicaprograms geminicaprograms commented Oct 25, 2023

The headOption operator returns the first element in Source wrapped in Some or None in case when source is empty or failed e.g.:

  Source.empty[Int].headOption()       // None
  Source.fromValues(1, 2).headOption() // Some(1)

The head operator returns the first element in Source or throws NoSuchElementException in case when it is either empty or receive() operation fails without error. In case when receive() fails with exception then this exception is re-thrown e.g.:

  Source.empty[Int].head()       // throws NoSuchElementException("cannot obtain head from an empty source")
  Source.fromValues(1, 2).head() // 1

Note that neither head nor headOption are idempotent operations.

The `headOption` operator returns the first element in `Source` wrapped
in `Some` or `None` in case when source is empty or failed e.g.:

  Source.empty[Int].headOption()       // None
  Source.fromValues(1, 2).headOption() // Some(1)

The `head` operator returns the first element in `Source` or throws
`NoSuchElementException` in case when it is either empty or `receive()`
operation fails without error. In case when `receive()` fails with
exception then this exception is re-thrown e.g.:

  Source.empty[Int].head()       // throws NoSuchElementException("cannot obtain head from an empty source")
  Source.fromValues(1, 2).head() // 1

Note that neither `head` nor `headOption` are idempotent operations.
@geminicaprograms geminicaprograms merged commit e28a268 into master Oct 26, 2023
4 checks passed
@geminicaprograms geminicaprograms deleted the feat_headOption_head branch October 26, 2023 13:44
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