Browse Source

refactor: simplify the code with maps:map/2

Thanks @thalesmg for the suggestion
Kjell Winblad 1 year ago
parent
commit
88c96e26de
1 changed files with 4 additions and 7 deletions
  1. 4 7
      apps/emqx_resource/src/emqx_resource_manager.erl

+ 4 - 7
apps/emqx_resource/src/emqx_resource_manager.erl

@@ -1499,14 +1499,11 @@ maybe_reply(Actions, From, Reply) ->
 
 -spec data_record_to_external_map(data()) -> resource_data().
 data_record_to_external_map(Data) ->
-    AddedChannelsList = maps:to_list(Data#data.added_channels),
-    AddedChannelsListWithoutConfigs =
-        [
-            {ChanID, maps:remove(config, Status)}
-         || {ChanID, Status} <- AddedChannelsList
-        ],
     AddedChannelsWithoutConfigs =
-        maps:from_list(AddedChannelsListWithoutConfigs),
+        maps:map(
+            fun(_ChanID, Status) -> maps:remove(config, Status) end,
+            Data#data.added_channels
+        ),
     #{
         id => Data#data.id,
         error => external_error(Data#data.error),