Distribution of Option
, Either
, Try
, scalaz.\/
, scalaz.Validation
on a large project that started in 2009 and has about ~425,000 SLOC of Scala:
› find . -name '*.scala' -exec grep -o "Option" {} \; | wc -l
7747
› find . -name '*.scala' -exec grep -o "Either" {} \; | wc -l
547
› find . -name '*.scala' -exec grep -o "Try" {} \; | wc -l
129
› find . -name '*.scala' -exec grep -o "\\\/" {} \; | wc -l
2159
› find . -name '*.scala' -exec grep -o "Validation" {} \; | wc -l
715
Caveats:
- Project was started in 2009
- Scalaz was introduced in early 2012
\/
was introduced August 2012- Project was upgraded to Scala 2.10 in winter of 2012-2013
Observations:
Option
is used extensively in data modeling and as failure abstraction when the reason for failure is not needed.\/
is the primary failure abstraction, which explains its rapid usage after introduction.Validation
is typically only used when accumulating errors but some code still uses it monadically. This code will be refactored over time, which will result in an overall decrease inValidation
usage.Try
is used occassionally when working with Futures but codebase prefersFuture[ErrorType \/ A]
.Either
is typically only used when the value represents two choices with no preference -- that is, the left side is equally correct/valid as the right side. Some older subsystems still useEither
as a failure abstraction and as they are refactored to usescalaz.\/
, theEither
usage will decrease.