Adding example of headOption operator (#29717)
Co-authored-by: Johan Andrén <johan@markatta.com>
This commit is contained in:
parent
fb1c6ff253
commit
1ff619259f
3 changed files with 42 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue