@@ -122,14 +122,23 @@ defmodule Jsonpatch do
122122 def diff ( source , destination )
123123
124124 def diff ( % { } = source , % { } = destination ) do
125- Map . to_list ( destination )
126- |> diff_adds_and_replaces ( source , "" )
125+ destination = Map . to_list ( destination )
126+
127+ acc = diff_adds_and_replaces ( destination , source , "" )
128+ acc = diff_removes ( destination , source , "" , acc )
129+
130+ acc
127131 end
128132
129133 def diff ( source , destination ) when is_list ( source ) and is_list ( destination ) do
130- Enum . with_index ( destination )
131- |> Enum . map ( fn { v , k } -> { k , v } end )
132- |> diff_adds_and_replaces ( source , "" )
134+ destination =
135+ Enum . with_index ( destination )
136+ |> Enum . map ( fn { v , k } -> { k , v } end )
137+
138+ acc = diff_adds_and_replaces ( destination , source , "" )
139+ acc = diff_removes ( destination , source , "" , acc )
140+
141+ acc
133142 end
134143
135144 def diff ( _ , _ ) do
@@ -144,6 +153,16 @@ defmodule Jsonpatch do
144153 defguardp are_unequal_lists ( val1 , val2 )
145154 when val1 != val2 and is_list ( val2 ) and is_list ( val1 )
146155
156+ defp diff_removes ( target , source , current_path , acc )
157+
158+ defp diff_removes ( [ ] , _ , _ , acc ) do
159+ acc
160+ end
161+
162+ defp diff_removes ( [ { key , val } | tail ] , source , current_path , acc ) do
163+ acc
164+ end
165+
147166 defp diff_adds_and_replaces ( target , source , current_path , acc \\ [ ] )
148167
149168 defp diff_adds_and_replaces ( [ ] , _ , _ , acc ) do
0 commit comments