Exercise

Create a function

We've seen how we can use safely() to identify non-reachable urls in the previous exercise: we wrote a little process that called a safe version of read_lines(), and returned a list of $errors.

In this exercise, we'll try another approach, as we won't focus on errors only. Instead of mapping a safe function and extracting the "error" elements from the results, we will write a helper function that will immediately discard() the NULL elements of the output of safe_read().

This way, instead of extracting the $error or $result part of the output, we'll be able to know if the elements are reachable (the content is returned in $results) or if it's not (then the error is returned in $error).

The urls vector has been provided for you.

Instructions

100 XP
  • Create a safe version of read_lines().

  • Create a function called safe_read_discard() that will run the safe version of read_lines() and discard() the NULL elements.

  • Map this function on the url list that has been provided for you.