aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/small_SUITE_data/src/maps1.erl
blob: 228ffe2c22a858d9463c5bd63b4446de303c67eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
%%
%% File:    maps1.erl
%% Author:  Björn-Egil Dahlberg
%% Created: 2014-01-17
%%

-module(maps1).

-compile([export_all]).


-export([recv/3, decode/1]).
-export([get_my_map/0,is_my_map/1]).

%-record(can_pkt, {id, data :: binary(), timestamp}).

-type can_pkt() :: #{ id => term(), data => binary(), timestamp => term() }.
-type channel() :: atom() | pid() | {atom(),_}.

-spec recv(<<_:64,_:_*8>>, fun((can_pkt()) -> R), channel()) -> R.
recv(Packet, Fun, Chan) ->
  #{id := Can_id, data := Can_data} = P = decode(Packet),
  Fun(P).

-spec decode(<<_:64,_:_*8>>) -> #{id => <<_:11>>,timestamp => char()}.
decode(<<_:12, Len:4, Timestamp:16, 0:3, Id:11/bitstring, 0:18,
	 Data:Len/binary, _/binary>>) ->
  #{id => Id, data => Data, timestamp => Timestamp}.



t1() ->
    #{bar=>fun t2/0}.

t2() -> ok.

-type map_state() :: #{ id => integer(), val => term() }.

-spec update(map_state(), term()) -> map_state().

update(#{ id := Id, val := Val } = M, X) when is_integer(Id) ->
    M#{ val := [Val,X] }.

%% key coalescing

-spec get_my_map() -> map().

get_my_map() ->
    #{labels  => [one, two],
      number  => 27,
      [1,2,3] => wer,
      {4,5,6} => sdf,
      kvok    => #{
	<<"wat">> => v,
	a => qwe,
	2 => asd,
	[1,2,3] => wer,
	{4,5,6} => sdf,
	"abc" => zxc
       }
     }.

-spec is_my_map(map()) -> 'ok'.

is_my_map(#{labels  := [one, two],
	    number  := 27,
	    [1,2,3] := wer,
	    {4,5,6} := sdf,
	    kvok := #{
	      <<"wat">> := v,
	      a := qwe,
	      2 := asd,
	      [1,2,3] := wer,
	      {4,5,6} := sdf,
	      "abc" := zxc
	     }
	   }) -> ok.