1%%
2%% File:    maps1.erl
3%% Author:  Björn-Egil Dahlberg
4%% Created: 2014-01-17
5%%
6
7-module(maps1).
8
9-compile([export_all]).
10
11
12-export([recv/3, decode/1]).
13
14%-record(can_pkt, {id, data :: binary(), timestamp}).
15
16-type can_pkt() :: #{ id => term(), data => binary(), timestamp => term() }.
17-type channel() :: atom() | pid() | {atom(),_}.
18
19-spec recv(<<_:64,_:_*8>>, fun((can_pkt()) -> R), channel()) -> R.
20recv(Packet, Fun, Chan) ->
21  #{id := Can_id, data := Can_data} = P = decode(Packet),
22  Fun(P).
23
24-spec decode(<<_:64,_:_*8>>) -> #{id => <<_:11>>,timestamp => char(),_ => _}.
25decode(<<_:12, Len:4, Timestamp:16, 0:3, Id:11/bitstring, 0:18,
26	 Data:Len/binary, _/binary>>) ->
27  #{id => Id, data => Data, timestamp => Timestamp}.
28
29
30
31t1() ->
32    #{bar=>fun t2/0}.
33
34t2() -> ok.
35
36-type map_state() :: #{ id => integer(), val => term() }.
37
38-spec update(map_state(), term()) -> map_state().
39
40update(#{ id := Id, val := Val } = M, X) when is_integer(Id) ->
41    M#{ val := [Val,X] }.
42
43t3() ->
44    foo(#{greger => 3, #{arne=>anka} => 45}, 1).
45
46foo(#{} = M, b) -> %% Error
47    M#{alfa => 42, beta := 1337}.
48
49t4() ->
50    case #{} of
51        #{} -> ok;
52        Mod -> Mod:function(#{literal => map}, another_arg) %% Error
53    end.
54