-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy patheffect-ref.cpp
More file actions
39 lines (32 loc) · 879 Bytes
/
effect-ref.cpp
File metadata and controls
39 lines (32 loc) · 879 Bytes
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
#include "purescript.h"
// Tested with package v4.1.0
FOREIGN_BEGIN( Effect_Ref )
exports["new"] = [](const boxed& val) -> boxed {
return [=]() -> boxed {
return dict_t{ {"value", val} };
};
};
exports["read"] = [](const boxed& ref) -> boxed {
return [=]() -> boxed {
return ref["value"];
};
};
exports["modify'"] = [](const boxed& f) -> boxed {
return [=](const boxed& ref) -> boxed {
return [=]() -> boxed {
boxed t = f(ref["value"]);
dict_t& mutableRef = *static_cast<dict_t*>(ref.get());
mutableRef["value"] = t["state"];
return t["value"];
};
};
};
exports["write"] = [](const boxed& val) -> boxed {
return [=](const boxed& ref) -> boxed {
return [=]() -> boxed {
dict_t& mutableRef = *static_cast<dict_t*>(ref.get());
return mutableRef["value"] = val;
};
};
};
FOREIGN_END