Created
February 9, 2018 00:06
-
-
Save huntc/983433b14fefaa43cab08f9b966e31db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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