blob: f01cc5e519087507f868cf714db9c27d7aac73aa (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
-module(rec_adt).
-export([new/0, get_a/1, get_b/1, set_a/2, set_b/2]).
-record(rec, {a :: atom(), b = 0 :: integer()}).
-opaque rec() :: #rec{}.
-spec new() -> rec().
new() -> #rec{a = gazonk, b = 42}.
-spec get_a(rec()) -> atom().
get_a(#rec{a = A}) -> A.
-spec get_b(rec()) -> integer().
get_b(#rec{b = B}) -> B.
-spec set_a(rec(), atom()) -> rec().
set_a(R, A) -> R#rec{a = A}.
-spec set_b(rec(), integer()) -> rec().
set_b(R, B) -> R#rec{b = B}.
|