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

Added s.pull.lastOrError #1609

Merged
merged 1 commit into from
Sep 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/shared/src/main/scala/fs2/Stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3959,6 +3959,13 @@ object Stream extends StreamLowPriority {
go(None, self)
}

/** Returns the last element of the input, if non-empty, otherwise fails the pull with a `NoSuchElementException`. */
def lastOrError(implicit F: RaiseThrowable[F]): Pull[F, INothing, O] =
last.flatMap {
case None => Pull.raiseError(new NoSuchElementException)
case Some(o) => Pull.pure(o)
}

/** Like [[uncons]] but does not consume the chunk (i.e., the chunk is pushed back). */
def peek: Pull[F, INothing, Option[(Chunk[O], Stream[F, O])]] =
uncons.flatMap {
Expand Down