“You are neither right nor wrong because the crowd disagrees with you. You are right because the data and reasoning are right.”
While reading the excellent Scala/FP book, Advanced Scala with Cats, I was just reminded that Scala’s
Either class was redesigned in Scala 2.12. Prior to 2.12,
Either was not biased, and didn’t implement
flatMap methods. As the image from the book shows,
Either is redesigned in 2.12 to include those methods, so it can now be used in Scala for-expressions as shown.
(I write about biasing in my book, Learning Functional Programming in Scala.)
“The Precogs are never wrong. But occasionally they do disagree.”
~ Minority Report
For the purposes of this simulation, imagine that you have three people that are each “right” roughly 80% of the time. For instance, if they take a test with 100 questions, each of the three individuals will get 80 of the questions right, although they may not get the same questions right or wrong. Given these three people, my question to several statisticians was, “If two of the people have the same answer to a given question, what are the odds that they are correct? Furthermore, if all three of them give the same answer to a question, what are the odds that they are right?”
Table of Contents
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 20.6, “Scala best practice: How to use the Option/Some/None pattern.”Back to top
For a variety of reasons, including removing
null values from your Scala code, you want to use what I call the Option/Some/None pattern. Or, if you’re interested in a problem (exception) that occurred while processing code, you may want to return Try/Success/Failure from a method instead of Option/Some/None.