Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: is Either the only Option?

In regard to potential runtime failures, like database queries, it seems that one must use some form of Either[String, Option[T]] in order to accurately capture the following outcomes:

  1. Some (record(s) found)
  2. None (no record(s) found)
  3. SQL Exception

Option simply does not have enough options.

I guess I need to dive into scalaz, but for now it's straight Either, unless I'm missing something in the above.

Have boxed myself into a corner with my DAO implementation, only employing Either for write operations, but am now seeing that some Either writes depend on Option reads (e.g. checking if email exists on new user signup), which is a majorly bad gamble to make.

Before I go all-in on Either, does anyone have alternate solutions for how to handle the runtime trifecta of success/fail/exception?

like image 973
virtualeyes Avatar asked Jan 19 '26 21:01

virtualeyes


1 Answers

Try Box from the fantastic lift framework. It provides exactly what you want.

See this wiki (and the links at the top) for details. Fortunately lift project is well modulized, the only dependency to use Box is net.lift-web % lift-common

like image 115
xiefei Avatar answered Jan 22 '26 09:01

xiefei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!