What's the relation of fold on Option, Either etc and fold on Traversable?
问题 Scalaz provides a method named fold for various ADTs such as Boolean , Option[_] , Validation[_, _] , Either[_, _] etc. This method basically takes functions corresponding to all possible cases for that given ADT. In other words, a pattern match shown below: x match { case Case1(a, b, c) => f(a, b, c) case Case2(a, b) => g(a, b) . . case CaseN => z } is equivalent to: x.fold(f, g, ..., z) Some examples: scala> (9 == 8).fold("foo", "bar") res0: java.lang.String = bar scala> 5.some.fold(2 *, 2)