Skip to content

Commit 537b787

Browse files
authored
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.
1 parent 13aa90a commit 537b787

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/scala/stdlib/Options.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ object Options extends FlatSpec with Matchers with org.scalaexercises.definition
9898
def foldOptions(res0: Int, res1: Int) {
9999
val number: Option[Int] = Some(3)
100100
val noNumber: Option[Int] = None
101-
val result1 = number.fold(0)(_ * 3)
102-
val result2 = noNumber.fold(0)(_ * 3)
101+
val result1 = number.fold(1)(_ * 3)
102+
val result2 = noNumber.fold(1)(_ * 3)
103103

104104
result1 should be(res0)
105105
result2 should be(res1)

0 commit comments

Comments
 (0)