# Using Try's fold

**URL:** <https://users.scala-lang.org/t/using-trys-fold/9081>\
**Category:** Question\
**Created:** [January 11, 2023, 4:00pm UTC](https://users.scala-lang.org/t/using-trys-fold/9081 "2023-01-11T16:00:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aschweig](https://users.scala-lang.org/user_avatar/users.scala-lang.org/aschweig/32/2531_2.png) [@aschweig](https://users.scala-lang.org/u/aschweig)\
**Post date:** [January 11, 2023, 4:00pm UTC](https://users.scala-lang.org/t/using-trys-fold/9081/1 "2023-01-11T16:00:00Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![aschweig](https://users.scala-lang.org/user_avatar/users.scala-lang.org/aschweig/32/2531_2.png) [@aschweig](https://users.scala-lang.org/u/aschweig)\
**Post date:** [January 11, 2023, 4:17pm UTC](https://users.scala-lang.org/t/using-trys-fold/9081/2 "2023-01-11T16:17:03Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![som-snytt](https://users.scala-lang.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@som-snytt](https://users.scala-lang.org/u/som-snytt)\
**Post date:** [January 11, 2023, 5:04pm UTC](https://users.scala-lang.org/t/using-trys-fold/9081/3 "2023-01-11T17:04:07Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![aschweig](https://users.scala-lang.org/user_avatar/users.scala-lang.org/aschweig/32/2531_2.png) [@aschweig](https://users.scala-lang.org/u/aschweig)\
**Post date:** [January 13, 2023, 10:02pm UTC](https://users.scala-lang.org/t/using-trys-fold/9081/4 "2023-01-13T22:02:15Z")

</div>

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