Skip to content

Instantly share code, notes, and snippets.

@ssanj
Created October 28, 2019 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssanj/2768a0883d561274dc69df81a6510ec6 to your computer and use it in GitHub Desktop.
Save ssanj/2768a0883d561274dc69df81a6510ec6 to your computer and use it in GitHub Desktop.
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