Adding example of headOption operator (#29717)

Co-authored-by: Johan Andrén <johan@markatta.com>
This commit is contained in:
Muskan Gupta 2020-10-12 12:57:46 +05:30 committed by GitHub
parent fb1c6ff253
commit 1ff619259f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,23 @@
/*
* Copyright (C) 2020 Lightbend Inc. <https://www.lightbend.com>
*/
package docs.stream.operators.sink
import akka.actor.ActorSystem
import akka.stream.scaladsl.{ Sink, Source }
import scala.concurrent.{ ExecutionContextExecutor, Future }
object HeadOption {
implicit val system: ActorSystem = ???
implicit val ec: ExecutionContextExecutor = system.dispatcher
def headOptionExample(): Unit = {
//#headoption
val source = Source.empty
val result: Future[Option[Int]] = source.runWith(Sink.headOption)
result.foreach(println)
//None
//#headoption
}
}