5.3 Multiple Return Values
A function can return more than one result. We’ve seen many examples of functions from standard packages that return two values, the desired computational result and an error value or boolean that indicates whether the computation worked. The next example shows how to write one of our own.
The program below is a variation of findlinks that makes the
HTTP request itself so that we no longer need to run fetch.
Because the HTTP and parsing operations can fail,
findLinks declares two results: the list of discovered links
and an error.
Incidentally, the HTML parser can usually recover from bad input and
construct a document containing error nodes, so Parse rarely fails; when it does, it’s typically due to underlying ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access