title: Hide state in function call
body: <p>I thinking about hide state from function call.
  Example:</p>
  
  <pre><code>body_to_client(Req, ClientRef) -&gt;
    case cowboy_req:body(Req) of
      {ok, Data, Req2} -&gt;
        ok = hackney:send_body(ClientRef, Data),
        Req2;
      {more, Data, Req2} -&gt;
        ok = hackney:send_body(ClientRef, Data),
        body_to_client(Req2, ClientRef)
    end.
  </code></pre>
  
  <p>But I want to divide this code on couple parts and hide implementation:</p>
  
  <pre><code>body_to_client(ReadRequestBody, ClientRef) -&gt;
    case ReadRequestBody() of
      {ok, Data} -&gt;
        ok = hackney:send_body(ClientRef, Data),
        ReadRequestBody;
      {more, Data} -&gt;
        ok = hackney:send_body(ClientRef, Data),
        body_to_client(ReadRequestBody, ClientRef)
    end.
  </code></pre>
  
  <p>Where ReadRequestBody is a function which contains all details and state.
  I think it should be something like this:</p>
  
  <pre><code>ReadRequestBody = fun() -&gt;
      {Status, Data, Req2} = cowboy_req:body(Req),
      {Status, Data}
    end
  </code></pre>
  
  <p>But I don't know how to deal with Req2 and pass it in next call.</p>