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:          count/1, count/2, count/3,
           first/1, first/2, first/3,
           all/1, all/2,
           view_loop/2, parse_view_options/1]).
  
  -spec all(Db::db()) -> {ok, Rows::list(ejson_object())} | {error, term()}.
  
negative.code:         ViewName::string()}, Options::view_options()) 
      -> integer() | {error, term()}.
  %% @doc count number of doc in a view (or all docs)
  count(#db{options=IbrowseOpts}=Db, ViewName, Options)->
      make_view(Db, ViewName, Options, fun(Args, Url) ->
          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
      end).
  
  -spec first(Db::db()) -> {ok, Row::ejson_object()} | {error, term()}.
  %% @equiv first(Db, 'all_docs', [])
  