Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import akka.NotUsed
import akka.stream.scaladsl.Flow
case object NotZero
// Emits either an Int when zero, or a domain object indicating
// that the Int is non zero. Use this approach instead of relying
// on exceptions. Exceptions are for exceptional conditions,
// largely unanticipated, and they will terminate a stream.
val flow: Flow[Int, Either[NotZero.type, Int], NotUsed] =
Flow[Int]
.map(n => if (n == 0) Right(n) else Left(NotZero))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.