Using Try's fold

Beginner question here. The below doesn’t work for me:

scala> scala.util.Try[String] { "S=" +  (1/0).toString }.fold[String] { t => t.toString } { s => s }
-- Error: ----------------------------------------------------------------------
1 |scala.util.Try[String] { "S=" +  (1/0).toString }.fold[String] { t => t.toString } { s => s }
  |missing argument for parameter fb of method fold in class Try: (fa: Throwable => String, fb: String => String): String
1 error found

What does the error message mean in this case? Should I be using match instead?

Answering my own question, I didn’t notice the form of fold.
The following works:

scala.util.Try[String] { "S=" +  (1/0).toString }.fold[String]({ t => t.toString}, {s => s })

The weird caret alignment may be due to cut/paste, and should look like:

1 |scala.util.Try[String] { "S=" +  (1/0).toString }.fold[String] { t => t.toString } { s => s }

I wonder if it would be clearer to highlight just the problematic parameter list.

I remember tweaking how these errors are reported for Scala 2, as they can be surprisingly cryptic.

Scala 2 lists up to 3 missing params, and if there are too many args, it says by how much.

That matters more with unfamiliar method signatures and also generated API with many parameters.

Sadly, a quick search shows that “trifold” is commonly used for things that fold, such as wallets and brochures. Probably “trifold threat” does not sound threatening.

In this case, Option’s fold blinded me to the correct behavior.