anchor.diff:              Error
       end.
   
  +-spec fold(Function::function(), Acc::list(), Db::db(), 
  +        ViewName::'all_docs' | {DesignName::string(), ViewName::string()})
  +    -> list(term()) | {error, term()}.
  +%% @equiv fold(Function, Acc, Db, ViewName, [])
  +fold(Function, Acc, Db, ViewName) ->
  +    fold(Function, Acc, Db, ViewName, []).
  +
  +-spec fold(Function::function(), Acc::list(), Db::db(), 
  +        ViewName::'all_docs' | {DesignName::string(),
  +        ViewName::string()}, Options::view_options())
  +    -> list(term()) | {error, term()}.
  +%% @doc call Function(Row, AccIn) on succesive row, starting with 
  +%% AccIn == Acc. Function/2 must return a new list accumultator or the
  +%% atom <em>done</em> to stop fetching results. Acc0 is returned if the 
  +%% list is empty. For example:
  +%% ```
  +%% couchbeam_view:fold(fun(Row, Acc) -> [Row|Acc] end, [], Db, 'all_docs').
  +%% '''
  +fold(Function, Acc, Db, ViewName, Options) ->
  +    case stream(Db, ViewName, self(), Options) of
  +        {ok, StartRef, ViewPid} ->
  +            fold_view_results(StartRef, ViewPid, Function, Acc);
  +        Error ->
  +            Error
  +    end.
  +
  +
  +%% ----------------------------------
  +%% utilities functions
  +%% ----------------------------------
  +
   -spec parse_view_options(Options::list()) -> view_query_args().
   %% @doc parse view options
   parse_view_options(Options) ->
  
positive.code: 
  %% @private
  
  do_count(Args, Url, IbrowseOpts) ->
      Result = case Args#view_query_args.method of
          get ->
              couchbeam_httpc:request(get, Url, ["200"], IbrowseOpts);
          post ->
              Body = ejson:encode({[{<<"keys">>, Args#view_query_args.keys}]}),
              Headers = [{"Content-Type", "application/json"}],
              couchbeam_httpc:request_stream(post, Url, ["200"],
                  IbrowseOpts, Headers, Body)
      end,
      case Result of
          {ok, _, _, RespBody} ->
              {Props} = ejson:decode(RespBody),
              case proplists:get_value("limit",
                      Args#view_query_args.options, 0) of
              0 ->
                  proplists:get_value(<<"total_rows">>, Props);
              _ ->
                  Rows = proplists:get_value(<<"rows">>, Props),
                  length(Rows)
              end;
          Error ->
              Error
      end.
  
  collect_view_first(Ref, Pid) ->
      receive
          {row, Ref, done} ->
  
negative.code:             Rows = lists:reverse(Acc),
              {error, Rows, Error}
      end.
  
  process_view_results(ReqId, Params, UserFun, Callback) ->
      receive
  