Skip to content
Permalink
Browse files

Added s.pull.lastOrError

  • Loading branch information...
mpilquist committed Sep 10, 2019
1 parent 028cb7f commit ef956faa023510395a19e0600036cf5af75cf1ae
Showing with 7 additions and 0 deletions.
  1. +7 −0 core/shared/src/main/scala/fs2/Stream.scala
@@ -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 {

0 comments on commit ef956fa

Please sign in to comment.
You can’t perform that action at this time.