anchor.diff:          Value -> Value
       end.
   
  --spec store(_, _, [#r{}]) -> _.
  +-spec store(id(), term(), replies()) -> replies().
   %% @private
   store(Id, Value, List) -> lists:keystore(Id, ?KEY, List, Value).
   
  --spec from_chunks([string()]) -> binary().
  +-spec from_chunks(#r{}) -> binary().
   %% @private
  -from_chunks(Chunks) -> iolist_to_binary(Chunks).
  -
  +from_chunks(#r{chunks = Chunks}) -> iolist_to_binary(Chunks).
  
positive.code: %% API
  %%
  
  empty() -> [].
  
  insert(Id, List) ->
      case lists:keymember(Id, ?KEY, List) of
          true  -> error("Cannot reset existing id");
          false -> store(Id, #r{id = Id}, List)
      end.
  
  set_status(Id, Status, List) ->
      case find(Id, List) of
          V when V#r.status =:= undefined -> store(Id, V#r{status = Status}, List);
          _Other                          -> error("Cannot update existing status")
      end.
  
  add_chunk(Id, Chunk, List) ->
      Value = find(Id, List),
      store(Id, Value#r{chunks = [Chunk|Value#r.chunks]}, List).
  
  completed(Id, List) ->
      Value = find(Id, List),
      store(Id, Value#r{pending = false}, List).
  
  pending(List) -> length([V || V <- List, V =:= pending]).
  
  
  merge([H|_]) -> {ok, 200, from_chunks(H#r.chunks)}.
  
  %%
  %% Private
  %%
  
  -spec find(_, [#r{}]) -> _.
  %% @private
  find(Id, List) ->
      case lists:keyfind(Id, ?KEY, List) of
  
negative.code:          pending/1,
           merge/1]).
  
  %%
  %% Types
  %%
  
  -type id() :: term()
  
  -record(r, {id             :: term(),
              status         :: undefined | string(),
              chunks = []    :: [string()],
              pending = true :: boolean()}).
  
  -opaque replies() :: [#r{}].
  
  -export_types([replies/0]).
  
  %%
  %% Macros
  %%
  
  -define(KEY, 2).
  
  