Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.04 KB | None | 0 0
  1. %%%-------------------------------------------------------------------
  2. %%% @author przemek
  3. %%% @copyright (C) 2020, <COMPANY>
  4. %%% @doc
  5. %%%
  6. %%% @end
  7. %%% Created : 03. kwi 2020 21:29
  8. %%%-------------------------------------------------------------------
  9. -module(pollution).
  10. -author("przemek").
  11.  
  12. -record(monitor, {stations = #{}, measurements = #{}}).
  13.  
  14. %% API
  15. -export([createMonitor/0, addStation/3]).
  16.  
  17. createMonitor() -> #monitor{}.
  18.  
  19. isStationExists(Station, Monitor) ->
  20.   case is_list(Station) of
  21.     true -> maps:is_key(Station, Monitor#monitor.stations);
  22.     _ -> case is_tuple(Station) of
  23.            true -> lists:member(Station, maps:values(Monitor#monitor.stations));
  24.            _ -> false
  25.          end
  26.   end.
  27.  
  28. addStation(Name, {X, Y}, Monitor) when is_list(Name) and is_float(X) and is_float(Y) and is_record(Monitor, monitor) ->
  29.   case isStationExists(Name, Monitor) of
  30.     false -> Monitor;
  31.     true -> #monitor{stations = maps:put(Name, {X,Y}, Monitor#monitor.stations), measurements = Monitor#monitor.measurements}
  32.   end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement