From 537b78761ae0ca377a85a72c6c03707c7b104ddb Mon Sep 17 00:00:00 2001 From: Kevin Greene Date: Fri, 5 May 2017 16:51:16 -0400 Subject: [PATCH] Update Options.scala Using `noNumber.fold(0)(_ * 3)` makes it unclear whether or not the default value goes through the same process. In other words, is the result 0 because that's the value we provide, or because `0 = 0 * 3`? Using `val result2 = noNumber.fold(1)(_ * 3)` makes it clearer, as the result is 1 and not 3. --- src/main/scala/stdlib/Options.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/stdlib/Options.scala b/src/main/scala/stdlib/Options.scala index d253a628..44643c28 100644 --- a/src/main/scala/stdlib/Options.scala +++ b/src/main/scala/stdlib/Options.scala @@ -98,8 +98,8 @@ object Options extends FlatSpec with Matchers with org.scalaexercises.definition def foldOptions(res0: Int, res1: Int) { val number: Option[Int] = Some(3) val noNumber: Option[Int] = None - val result1 = number.fold(0)(_ * 3) - val result2 = noNumber.fold(0)(_ * 3) + val result1 = number.fold(1)(_ * 3) + val result2 = noNumber.fold(1)(_ * 3) result1 should be(res0) result2 should be(res1)