Hi,
I haven't worked with
JsResult before, but it looks like an either-or type (an instance is either a JsSuccess or a JsError), somewhat similar to a Scala Option (either a Some or a None).
Option offers a fold() method, too, which has been criticized for a lack of readability. See, for example, "
Option.fold() considered unreadable".
I imagine those criticisms would also apply to JsResult's fold().
In fact, the authors of Play's "
JSON basics" documentation (what I believe you were looking at) pretty much admit there's a readability issue: there's no programmatic reason to specify the argument names as they do...
fold(invalid = ..., valid = ...)
...so I presume they did it to reduce confusion.
So yeah, I think pattern matching would be better. Or, maybe you could do some kind of JsResult.map(...).getOrElse(...) construction, as the above blog post does with Option?
Dan