scala - How to end an infinite akka stream -


i'm new akka streams have case want use permutations infinite source. simplified example finite source this.

val future = source(1 100)     .map { => if (i % 20 == 0) println(i); }     .filter(_ == 42)     .runwith(sink.fold[int, int](0)(keep.right)) 

this exemple outputs:

20 40 60 80 100 

i'm fine source getting past 42 don't want exhaust entire stream before being able result.

val result: int = await.result(future, 1.second) result should be(42) 

question is, how should end stream when i've found i'm looking for?

val future = source(1 100)     .map { => if (i % 20 == 0) println(i); }     .filter(_ == 42)     .runwith(sink.head) 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -