title: How to refactor functional error handling in flutter with dartz
body: <p>I have two methods</p>
  <pre><code>@override
    Future&lt;Option&lt;StorageFailure&gt;&gt; init() async {
      final root = await getRootDir();
      return root.fold(
        (failure) =&gt; some(failure),
        (dir) {
          final images = Directory(&quot;$dir/images&quot;);
          final videos = Directory(&quot;$dir/videos&quot;);
          images.create(); // more error handling here (try|either)
          videos.create();
        },
      );
    }
  
    @override
    Future&lt;Either&lt;StorageFailure, Directory&gt;&gt; getRootDir() async {
      try {
        final root = await getApplicationDocumentsDirectory();
        return right(Directory(&quot;${root.path}/files&quot;));
      } catch (e) {
        return left(StorageFailure(reason: e.toString()));
      }
    }
  </code></pre>
  <p>On the <code>init</code> method after folding i need to do more error handling but i don't like to nest too much my code. Also i don't know how to return a <code>Failure</code> from the <code>right</code> function.</p>
  <p>What would be a better way to chain those values?</p>