anchor.diff:  
   -define(TEST_TIME_SECONDS, 10).
   
  -eqc_test_() ->
  -    {timeout, ?TEST_TIME_SECONDS+5, [?_assert(test_split() =:= true)]}.
  -
  -test_split() ->
  -    test_split(?TEST_TIME_SECONDS).
  -
  -test_split(TestTimeSeconds) ->
  -    eqc:quickcheck(eqc:testing_time(TestTimeSeconds, ?QC_OUT(prop_split()))).
  -
  -prop_split() ->
  -    ?FORALL(Ops, oneof([riak_dt_map:gen_op(), riak_dt_orswot:gen_op()]),
  -            begin
  -                {Pre, Post} = split_ops(Ops),
  -                AgOps = to_list(Ops),
  -                ?WHENFAIL(
  -                   begin
  -                       io:format("Generated Ops ~p~n", [Ops]),
  -                       io:format("Split Pre ~p~n", [Pre]),
  -                       io:format("Split Post ~p~n", [Post])
  -                   end,
  -                   collect(with_title("operation length"), length(AgOps),
  -                           collect(with_title("operation depth"), depth(AgOps, 0),
  -                                   conjunction([
  -                                                {pre, only_rem_ops(Pre)},
  -                                                {post, only_add_ops(Post)}
  -                                               ])))
  -                  )
  -            end).
  -
  -to_list({update, Ops}) ->
  -    Ops;
  -to_list(Op) ->
  -    [Op].
  -
  -depth({update, Ops}, Depth) ->
  -    depth(Ops, Depth);
  -depth([], Depth) ->
  -    Depth;
  -depth([{update, {_Name, ?MAP_TYPE}, {update, Ops}}| Rest], Depth) ->
  -    max(depth(Ops, Depth +1), depth(Rest, Depth));
  -depth([_Op | Rest], Depth) ->
  -    depth(Rest, Depth).
  -
  -only_type_ops(_TestFun, []) ->
  -    true;
  -only_type_ops(TestFun, [Op | Rest]) ->
  -    case TestFun(Op) of
  -        false ->
  -            false;
  -        true ->
  -            only_type_ops(TestFun, Rest)
  -    end.
  -
  -only_add_ops({update, Ops}) ->
  -    only_add_ops(Ops);
  -only_add_ops(Ops) ->
  -    only_type_ops(fun is_add_op/1, Ops).
  -
  -only_rem_ops({update, Ops}) ->
  -    only_rem_ops(Ops);
  -only_rem_ops(Ops) ->
  -    only_type_ops(fun is_rem_op/1, Ops).
  -
  -is_add_op({update, {_Name, _}, {update, Ops}}) ->
  -    only_add_ops(Ops);
  -is_add_op(Op) ->
  -    not is_rem_op(Op).
  -
  -is_rem_op({update, {_Name, _}, {update, Ops}}) ->
  -    only_rem_ops(Ops);
  -is_rem_op({update, {_Name, _}, {remove, _E}}) ->
  -    true;
  -is_rem_op({update, {_Name, _}, {remove_all, _Es}}) ->
  -    true;
  -is_rem_op({remove, _Key}) ->
  -    true;
  -is_rem_op({remove_all, _Elems}) ->
  -    true;
  -is_rem_op({update, _Key, {remove, _Elem}}) ->
  -    true;
  -is_rem_op(_Op) ->
  -    false.
   
   -endif.
   -endif.
  
positive.code:             {Meta, Record, Value}
      end.
  
  %% @private Takes an update operation and splits it into two update
  %% operations.  returns {pre, post} where pre is an update operation
  %% that must be a applied to a context _before_ it is merged with
  %% local replica state and post is an update operation that must be
  %% applied after the context has been merged with the local replica
  %% state.
  %%
  %% Why?  When fields are removed from Maps or elements from Sets the
  %% remove must be applied to the state observed by the client.  If a
  %% client as seen a field or element in a set, but the replica
  %% handling the remove has not then a confusing preconditione failed
  %% error will be generated for the user.
  %%
  %% The reason for applying remove type operations to the context
  %% before the merge is to ensure that only the adds seen by the client
  %% are removed, and not adds that happen to be present at this
  %% replica.
  %%
  %% @TODO optimise the case where either Pre or Post comes back
  %% essentially as a No Op (for example, and update to a nested Map
  %% that has no operations. While this does not affect correctness, it
  %% is not ideal.
  split_ops({AddOp, _}=Op) when AddOp == add;
                                AddOp == add_all ->
      {{update, []}, {update, [Op]}};
  split_ops({RemOp, _}=Op) when RemOp == remove;
                                RemOp == remove_all ->
      {{update, [Op]}, {update, []}};
  split_ops({update, Ops}) ->
      %% Map or Set update list
      {Pre, Post} = split_ops(Ops, [], []),
      {{update, Pre}, {update, Post}}.
  
  split_ops([], Pre, Post) ->
      {lists:reverse(Pre), lists:reverse(Post)};
  split_ops([{remove, _Key}=Op | Rest], Pre, Post) ->
      split_ops(Rest, [Op | Pre], Post);
  split_ops([{remove_all, _Elems}=Op | Rest], Pre, Post) ->
      split_ops(Rest, [Op | Pre], Post);
  split_ops([{update, Key, {remove, _}}=Op | Rest], Pre, Post) ->
      split_ops(Rest, [Op | Pre], [{add, Key} | Post]);
  split_ops([{update, Key, {remove_all, _}}=Op | Rest], Pre, Post) ->
      split_ops(Rest, [Op | Pre], [{add, Key} | Post]);
  split_ops([{update, {_Name, _}=Key, {update, Ops}} | Rest], Pre0, Post0) when is_list(Ops) ->
      {Pre, Post} = split_ops(Ops,[], []),
      Pre1 = maybe_prepend(Key, Pre, Pre0),
      Post1 = maybe_prepend(Key, Post, Post0),
      split_ops(Rest, Pre1, [{add, Key} | Post1]);
  split_ops([Op | Rest], Pre, Post) ->
      split_ops(Rest, Pre, [Op | Post]).
  
  
  maybe_prepend(_Key, [], Acc) ->
      Acc;
  maybe_prepend(Key, Ops, Acc) ->
      [{update,Key,{update, Ops}} | Acc].
  %% This uses an exported but marked INTERNAL
  %% function of `riak_object:set_contents' to preserve
  %% non-crdt sibling values and Metadata
  
negative.code: %% ===================================================================
  -ifdef(TEST).
  
  
  -ifdef(EQC).
  -define(QC_OUT(P),
  