Skip to content

Instantly share code, notes, and snippets.

@marianoguerra
Created December 31, 2017 16:57
Show Gist options
  • Save marianoguerra/94f8594d455a37f01bed3134bdc6efef to your computer and use it in GitHub Desktop.
Save marianoguerra/94f8594d455a37f01bed3134bdc6efef to your computer and use it in GitHub Desktop.
First attempts at using lasp
{ok, {MapId, _, _, _}} = lasp:declare({<<"mymap">>, {state_awmap, [state_mvregister]}}, {state_awmap, [state_mvregister]}).
K1 = <<"key1">>.
V1 = #{what => i_am_a_gmap_value, thing => 42}.
{ok, {MapId1, _, _, _}} = lasp:update(MapId, {apply, K1, {set, erlang:unique_integer([monotonic, positive]), V1}}, self()).
{ok, Res1} = lasp:query(MapId1).
Res1.
% {ok,[{<<"key1">>, {set, ...#{thing => 42,what => i_am_a_gmap_value} ... }}]}
sets:to_list(element(2, hd(Res1))).
% #{thing => 42,what => i_am_a_gmap_value}
{ok, {GMapId, _, _, _}} = lasp:declare({<<"mygmap">>, {state_gmap, [state_lwwregister]}}, {state_gmap, [state_lwwregister]}).
K1 = <<"key1">>.
V1 = #{what => i_am_a_gmap_value, thing => 42}.
{ok, {GMapId1, _, _, _}} = lasp:update(GMapId, {apply, K1, {set, erlang:unique_integer([monotonic, positive]), V1}}, self()).
{ok, Res2} = lasp:query(GMapId1).
Res2.
% [{<<"key1">>,#{thing => 42,what => i_am_a_gmap_value}}]
element(2, hd(Res2)).
% #{thing => 42,what => i_am_a_gmap_value}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment