Created
October 28, 2019 12:29
-
-
Save ssanj/2768a0883d561274dc69df81a6510ec6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type ErrorOr[A] = Either[String, A] | |
def errors(error: String): () => ErrorOr[Int] = () => { | |
println(s"running $error") | |
Left(error) | |
} | |
scala> val item1 = errors("error1") | |
item1: () => ErrorOr[Int] = $$Lambda$4361/1034150118@23f4a773 | |
scala> val item2 = errors("error2") | |
item2: () => ErrorOr[Int] = $$Lambda$4361/1034150118@7c691bb6 | |
scala> item1() >> item2() | |
running error1 //only runs item1 | |
res5: ErrorOr[Int] = Left(error1) | |
scala> item1() *> item2() | |
running error1 //runs item1 | |
running error2 //runs item2 | |
res6: ErrorOr[Int] = Left(error1) //only uses output from item on the right (item2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment